i have the situation: i'm showing many lines from the DB on the page. just creating dynamic lines (<% foreach (res in DBVar) %>
). Every line has a button. every button use just 1 OnClick method. I really dont care of the name(value) of these buttons, but i can't take, how can i pass a parameter (e.g. a ID of a line from DB (res.ID
)) from the .aspx page to OnClick Method. (Using LINQ to SQL)
I tried to take my param to the name(value) of a button with "<input type="button" value="<%= "string"+DBVar.ID%>
" and so on. the runat=server even can't take the variable on the name(value) coz of this i used just input method.
Use OnCommand event and assign CommandArgument
<asp:Button ID="Button1" runat="server" Text="Submit" CommandArgument='<%= res.ID %>' OnCommand="Button1_Click" />
in code behind
protected void Button1_Click(Object sender, CommandEventArgs e)
{
string ID=e.CommandArgument.ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With