You must Sign In to post a response.
  • Category: ASP.NET

    Button click inside Page_init method?

    What happens if calling the button click event in Page_Init?

    protected void Page_Init( object sender, EventArgs e)
    {
    this.btn.Click += new EventHandler(btn_Click);

    }
  • #765595
    Hi,
    It will call button_click event successfully.
    Try calling button_click as follows:
    btn_Click(sender, e)

  • #765598
    So before Page gets loading, on initial stage itself, button click event is getting called! correct?

  • #765600
    Hi lily,

    Init event is raised before page gets loaded, so the event is called at initial stage itself, you don't worry about that. You need to trigger that event when you require.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765617
    The Page_Init event is the first to occur, when an ASP.NET page is executed. This is where you perform any initialization steps that you need to set up or create instances of server controls. You can't access controls in this event because there is no guarantee that they have been created yet. Controls are created during this event, and you can control whether your attempt to use these objects will be denied by the server processing your request.
    The Page_Init event fires only the first time the page is loaded. When you postback to any page, the Page_Init event doesn't fire.

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]


Sign In to post your comments