Control design

M

Mark

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
 
K

Kevin Spencer

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
 
M

Mark

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 said:
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 said:
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
 
M

Mark

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 said:
Hi Mark,

You can use the OnItemCommand of the repeater. Check the url below for an
example;

http://msdn.microsoft.com/library/d...ebcontrolsdatagridclassonitemcommandtopic.asp

You can also do the same with a datagrid, and you would have more options.

Hope this helps,

Ethem Azun

Mark said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top