Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
315
adding a button at run time
posted

I need to be able to add multiple buttons at run time.

Although adding the buttons is easy enough I can't find how to tell it what sub routine in the back end to run when it's clicked. You can change the command name and argument, and you can also set it to run a specific sub at the client side (MyButton.ClientSideEvents.Click = "MySub"), but I can't find anything to tell it which sub to run at the back end as I don't want it to be client side.

Any help appreciated!

  • 995
    posted

    In addition, if you want to run different subs based on which button has been clicked you can use CommandName as identifier and call different sub routines inside the button click event handler:

    void button_Click(object sender, ButtonEventArgs e)

        {

            WebImageButton button = (WebImageButton)sender;

            if(button.CommandName == "sub1")

                SubRoutine1();

            else

                SubRoutine2();

            return;

        }


    --------------------------------------------------------------------------------


    Sincerely,
    Batnasan
    Developer Support Engineer, MCAD
    Infragistics
    www.infragistics.com/support

  • 355
    Suggested Answer
    Offline posted

    Dalereed,

    You should be able to do something along the lines of:

    WebImageButton button = new WebImageButton();
    button.Click += button_Click;
    
    void button_Click(object sender, ButtonEventArgs e)
    {
    	// code to handle the button click
    }
    

    This will cause the clicking of the button to cause a post back and run the button_Click method server side.