I am trying to fire an event, by clicking a button, and it does not fire. The id is
"Update".
Instead of going to the event handling paragraph, code goes to the Page_Load method
and skips the Update_Click method. The event is wired to the Update_Click method.
I have done this before, and never had a problem. (The Update_Click) method is created
by double clicking the button “Update”).
For example –
public partial class WebForm2 : System.Web.UI.Page
{
public string employee;
public decimal employeeDec;
public string empName;
public string date1;
public string date2;
public List<AccessForm> AccessFormList;
// following code skipped
protected void Update_Click(object sender, EventArgs e)
{
AccessFormUpdateDB.UpdateSelectedEmployee(AccessFormList);
}
//code executes here
protected void Page_Load(object sender, EventArgs e)
{
employee = ((TextBox)Page.Pr
1
Expert's answer
2012-06-05T09:37:39-0400
There could be several reasons. But the most probable is that your event is not subscribed. You can do it in the markup <asp:Button runat="server" id="Update" OnClick="Update_Clikck"/> or in code-behind on in the Init or Page load event:
protected override void OnInit(EventArgs e)
{
Update.Click += Update_Click;
}
Also make sure you don't have anywhere in the code something that overrides event subscription or reinitializes button like Update=new Button();
Comments
Leave a comment