Reputation: 689
I have a HTML control ie. Button. PFB Snippet
<button type="button" id="Button7" onserverclick="btnSave_OnClick"
runat="server" commandname="SaveNext">
Next
</button>
I am calling a same server side method from 2 different Button. I need to validate which button is clicked using CommandName in method.
Code behind:
protected void btnSave_OnClick(object sender, EventArgs e)
{
}
The problem is EventArgs e
does not have CommandName . I changed method parameter to commandeventargs e
which gives error as it requires EventArgs e
I am not preferring to change the HTML control to a asp:button
.
Please suggest.
Upvotes: 0
Views: 256
Reputation: 73731
In the server-side event handler, you can retrieve the CommandName
from the attributes of the button:
protected void btnSave_OnClick(object sender, EventArgs e)
{
HtmlButton btn = sender as HtmlButton;
string commandName = btn.Attributes["CommandName"];
...
}
Upvotes: 2