2009-05-28 6 views
7

Cercando di passare alcuni valori in un evento ImageButton clic, qualcosa di simile:Come faccio a passare i valori in un evento clickbutton image in C#?

<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')"/> 

poi nel codice dietro:

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

risposta

15

Prova utilizzando OnCommand invece di OnClick

Poi è possibile specificare valori nel CommandName & CommandArgument Proprietà

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

E

protected void blah_Command(object sender, CommandEventArgs e) 
{ 
    string val1 = e.CommandName.ToString(); 

    string [] othervals = e.CommandArgument.ToString().Split(','); 

} 
+0

applausi Eoin, che dovrebbe fare il lavoro bene! –

Problemi correlati