Home > Archive > ASP .NET > September 2004 > Control design
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi,
I'm just having a few problems working through the design of some
controls. Basically i want to have link (linkbutton etc) that will do
postback, in my case do a delete, but it needs your standard ID (the
primary key in the db). The way i'm doing it now is:
url link to same page:
page.aspx?command=delete&id=123
eg. return to the same page it's on
and have a method that captues this and does the delete
eg.
string isDelete = Request.Params["command"];
if(isDelete=="Delete")
{
string id = Request.Params["Room"];
doDelete(id);
}
It works, but seems a bad way to do it in terms of asp.net where other
controls do postback without such work-arounds.
The main problem i can't understand is the url in a repeater control
<asp:Repeater id="myreater" runat="server">
<ItemTemplate>
<a href="page.aspx?do=delete&id=<%#DataBinder.Eval(Container.DataItem,
"Notice_text")%>" > Delete something </a>
</ItemTemplate>
</asp:Repeater>
How would i get the individual id of the item from that link button
like in a onClick event in a datagrid control.
I'd like to just have a linkbutton that has an onClick even that takes
the id and deletes that item within the same page.
Would i have to create my own control?
Any help would be most appreciated,
thanks
| |
| Ethem Azun 2004-09-30, 11:37 am |
|
Hi Mark,
You can use the OnItemCommand of the repeater. Check the url below for an
example;
http://msdn.microsoft.com/library/d...ommandtopic.asp
You can also do the same with a datagrid, and you would have more options.
Hope this helps,
Ethem Azun
"Mark" wrote:
> Hi,
> I'm just having a few problems working through the design of some
> controls. Basically i want to have link (linkbutton etc) that will do
> postback, in my case do a delete, but it needs your standard ID (the
> primary key in the db). The way i'm doing it now is:
>
> url link to same page:
> page.aspx?command=delete&id=123
>
> eg. return to the same page it's on
> and have a method that captues this and does the delete
> eg.
> string isDelete = Request.Params["command"];
> if(isDelete=="Delete")
> {
> string id = Request.Params["Room"];
> doDelete(id);
> }
>
>
> It works, but seems a bad way to do it in terms of asp.net where other
> controls do postback without such work-arounds.
>
> The main problem i can't understand is the url in a repeater control
>
> <asp:Repeater id="myreater" runat="server">
> <ItemTemplate>
> <a href="page.aspx?do=delete&id=<%#DataBinder.Eval(Container.DataItem,
> "Notice_text")%>" > Delete something </a>
> </ItemTemplate>
> </asp:Repeater>
>
>
> How would i get the individual id of the item from that link button
> like in a onClick event in a datagrid control.
> I'd like to just have a linkbutton that has an onClick even that takes
> the id and deletes that item within the same page.
> Would i have to create my own control?
>
> Any help would be most appreciated,
> thanks
>
| |
| Ethem Azun 2004-09-30, 11:37 am |
|
Hi Mark,
You can use the OnItemCommand of the repeater. Check the url below for an
example;
http://msdn.microsoft.com/library/d...ommandtopic.asp
You can also do the same with a datagrid, and you would have more options.
Hope this helps,
Ethem Azun
"Mark" wrote:
> Hi,
> I'm just having a few problems working through the design of some
> controls. Basically i want to have link (linkbutton etc) that will do
> postback, in my case do a delete, but it needs your standard ID (the
> primary key in the db). The way i'm doing it now is:
>
> url link to same page:
> page.aspx?command=delete&id=123
>
> eg. return to the same page it's on
> and have a method that captues this and does the delete
> eg.
> string isDelete = Request.Params["command"];
> if(isDelete=="Delete")
> {
> string id = Request.Params["Room"];
> doDelete(id);
> }
>
>
> It works, but seems a bad way to do it in terms of asp.net where other
> controls do postback without such work-arounds.
>
> The main problem i can't understand is the url in a repeater control
>
> <asp:Repeater id="myreater" runat="server">
> <ItemTemplate>
> <a href="page.aspx?do=delete&id=<%#DataBinder.Eval(Container.DataItem,
> "Notice_text")%>" > Delete something </a>
> </ItemTemplate>
> </asp:Repeater>
>
>
> How would i get the individual id of the item from that link button
> like in a onClick event in a datagrid control.
> I'd like to just have a linkbutton that has an onClick even that takes
> the id and deletes that item within the same page.
> Would i have to create my own control?
>
> Any help would be most appreciated,
> thanks
>
| |
| Kevin Spencer 2004-09-30, 11:37 am |
| Hi Mark,
You have more problems than you realize. Putting a command to delete a
specific record by ID into a QueryString is a major mistake. Once somebody
knows what the QueryString does, they can indiscriminately delete records in
your database by simply typing URLs into their browser!
You might want to re-think your design.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Mark" <shadow.demon@gmail.com> wrote in message
news:b7061a4e.0409292119.69eb4080@posting.google.com...
> Hi,
> I'm just having a few problems working through the design of some
> controls. Basically i want to have link (linkbutton etc) that will do
> postback, in my case do a delete, but it needs your standard ID (the
> primary key in the db). The way i'm doing it now is:
>
> url link to same page:
> page.aspx?command=delete&id=123
>
> eg. return to the same page it's on
> and have a method that captues this and does the delete
> eg.
> string isDelete = Request.Params["command"];
> if(isDelete=="Delete")
> {
> string id = Request.Params["Room"];
> doDelete(id);
> }
>
>
> It works, but seems a bad way to do it in terms of asp.net where other
> controls do postback without such work-arounds.
>
> The main problem i can't understand is the url in a repeater control
>
> <asp:Repeater id="myreater" runat="server">
> <ItemTemplate>
> <a href="page.aspx?do=delete&id=<%#DataBinder.Eval(Container.DataItem,
> "Notice_text")%>" > Delete something </a>
> </ItemTemplate>
> </asp:Repeater>
>
>
> How would i get the individual id of the item from that link button
> like in a onClick event in a datagrid control.
> I'd like to just have a linkbutton that has an onClick even that takes
> the id and deletes that item within the same page.
> Would i have to create my own control?
>
> Any help would be most appreciated,
> thanks
| |
|
| Thanks for the warning, but the user can only delete things they have
permission to. A permissions check is done before the record is
erased. :D
"Kevin Spencer" <kspencer@takempis.com> wrote in message news:<#oLTXyupEHA.3572@TK2MSFTNGP10.phx.gbl>...[color=darkred]
> Hi Mark,
>
> You have more problems than you realize. Putting a command to delete a
> specific record by ID into a QueryString is a major mistake. Once somebody
> knows what the QueryString does, they can indiscriminately delete records in
> your database by simply typing URLs into their browser!
>
> You might want to re-think your design.
>
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
>
> "Mark" <shadow.demon@gmail.com> wrote in message
> news:b7061a4e.0409292119.69eb4080@posting.google.com...
| |
|
| Thanks the idea, will research it bit. Unfortately i had to move away
from a repeater (long story involving trying to find a way of doing a
batch of stored procedures, which i couldn't work out how to do) and
was wondering if there is a way to use a linkbutton and pass the ID as
a param to the linkbutton OnClick() ?
"Ethem Azun" <EthemAzun@discussions.microsoft.com> wrote in message news:<385D1FA7-565E-489F-BF9F-8F713A3FAE8C@microsoft.com>...[color=darkred]
> Hi Mark,
>
> You can use the OnItemCommand of the repeater. Check the url below for an
> example;
>
> http://msdn.microsoft.com/library/d...ommandtopic.asp
>
> You can also do the same with a datagrid, and you would have more options.
>
> Hope this helps,
>
> Ethem Azun
>
> "Mark" wrote:
>
|
|
|
|
|