8

Trying to pass some values into an imagebutton 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 code behind:

    protected void ImageButton_Click(object sender, ImageClickEventArgs e, string value1, string value2)
    {
       Response.Write(Value2);
    }

1 Answer 1

16

Try using OnCommand instead of OnClick

Then you can specify values in the CommandName & 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(',');

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.