How to pass values ​​to clickbutton event in C #?

Trying to pass some values ​​to the clickbutton click event, something like this:

<asp:ImageButton id="imagebutton1" runat="server" AlternateText="5 Star Luxury Villas in North Cyprus" ImageUrl="/download/1/luxury_villas.jpg" OnClick="ImageButton_Click('value1', 'value2')"/> 

then in the code behind:

  protected void ImageButton_Click(object sender, ImageClickEventArgs e, string value1, string value2) { Response.Write(Value2); } 
+7
source share
1 answer

Try using OnClick instead of OnClick

Then you can specify values ​​in CommandName and CommandArgument Properties

 <asp:ImageButton ID="blah" runat="server" OnCommand="blah_command" CommandName="val1" CommandArgument="val2,val3,val4" /> 

and

 protected void blah_Command(object sender, CommandEventArgs e) { string val1 = e.CommandName.ToString(); string [] othervals = e.CommandArgument.ToString().Split(','); } 
+15
source share

All Articles