This is a migrated thread and some comments may be shown as answers.

How can call OnClientClick function from programmatic created Rad Button?

2 Answers 396 Views
Button
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 28 Jul 2012, 06:36 AM
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 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jul 2012, 05:37 AM
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.
0
Slav
Telerik team
answered on 01 Aug 2012, 03:52 PM
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.
Tags
Button
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Slav
Telerik team
Share this question
or