Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameters through onclick event in asp

I've been trying to pass parameters through the onclick event using asp as follows:

<asp:Button runat="server" ID="btnUpdateFacturaID" style="display:none;" onclick="btnUpdateFacturaID_Click" CommandArgument="test" />

And on the other side:

protected void btnUpdateFacturaID_Click(object sender, CommandEventArgs e)
{
    string s = e.CommandArgument.ToString();
}

But I receive an error of no overload for 'btnUpdateFacturaID_Click' mathes delegate 'System.EventHandler'

In fact, I had initially the functions as follows:

protected void btnUpdateFacturaID_Click(object sender, EventArgs e)
{
    string s = e.CommandArgument.ToString();
}

But this way I can't (or I don't actually know, which is much more probable) pass parameters through the event. What amb I missing?

like image 781
Miquel Coll Avatar asked Oct 24 '25 21:10

Miquel Coll


1 Answers

Try this :

protected void btnUpdateFacturaID_Click(Object sender, EventArgs e)
{
     Button btn = (Button)sender;
     //do whatever with 
     //btn.CommandArgument.ToString()
}

enter image description here

like image 178
Royi Namir Avatar answered Oct 27 '25 11:10

Royi Namir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!