Miquel Coll
Miquel Coll

Reputation: 771

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?

Upvotes: 4

Views: 3553

Answers (1)

Royi Namir
Royi Namir

Reputation: 148524

Try this :

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

enter image description here

Upvotes: 3

Related Questions