How can call OnClientClick function from programmatic created Rad Button?

3 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    17 posts
    Member since:
    May 2011

    Posted 28 Jul 2012 Link to this post

    I have created a Rad Button on Page_Init Method for Contenet Palce Holder. I want call onClientClickEvent whenever i click on it.

    For Example:

    RadButton b = new RadButton();
    b.ID = "btnAddNew";
    b.Text = Resources.GetText("Add");
    b.CommandName = "Add";
    b.Skin = "Office2010Silver";              
    b.AutoPostBack = false;
    b.Icon.PrimaryIconCssClass = "actionBarAdd";
    b.Attributes.Add("OnClientClicked", "UsersActionButtonClicked()");

    Thanks,
    Sandeep
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 30 Jul 2012 Link to this post

    Hi Sandeep,

    Please modify your code as follows to achieve your scenario.

    C#:
    protected void ContentPlaceHolder1_Init(object sender, EventArgs e)
     {
       RadButton b = new RadButton();
       b.ID = "btnAddNew";
       b.Text = Resources.GetText("Add");
       b.CommandName = "Add";
       b.Skin = "Office2010Silver";
       b.AutoPostBack = false;
       b.Icon.PrimaryIconCssClass = "actionBarAdd";
       b.Attributes.Add("OnClick", "return UsersActionButtonClicked()");
       ContentPlaceHolder1.Controls.Add(b);
     }

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 01 Aug 2012 Link to this post

    Hi Sandeep,

    Please check this help article as it explains the handling of the client-side click event of RadButton. When specifying the event handler from the code behind, set the name of the handler function to the property  OnClientClicked of RadButton:
    RadButton1.OnClientClicked = "OnClientClicked"

    Regards,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top