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

OnClick event not fire

4 Answers 419 Views
Button
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 21 Jun 2013, 06:07 AM
Hi,

It maybe is a bug.

OnClick event will not fire when set_enabled(false) at the client site before submit .

Here is my code:
protected void Page_Load(object sender, EventArgs e)
    {
ScriptManager.RegisterOnSubmitStatement(
            Page, GetType(), "Onsubmit1",
            string.Format(@"var button = $find('{0}');button.set_enabled(false);"
                          , RadButton1.ClientID));
}
protected void RadButton1_Click(object sender, EventArgs e)
    {
        RadButton1.Text = "Click";
    }

in aspx:
  <telerik:RadButton ID="RadButton1" runat="server"  Text="Confirm" OnClick="RadButton1_Click"  >
            </telerik:RadButton>

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jun 2013, 11:53 AM
Hi Eric,

I have tried to replicate your issue.The OnClick event is not firing because ,you have set it on the Page_Load event.If you want to disable the button only for the first time then put the code in !IsPostBack .Try the following code snippet.

C#:
protected void Page_Load(object sender, EventArgs e)
{
 if (!IsPostBack)
  {
   ScriptManager.RegisterOnSubmitStatement(Page, GetType(), "Onsubmit1", string.Format(@"var button = $find('{0}');button.set_enabled(false);", RadButton1.ClientID));
  }
}

Thanks,
Shinu
0
Eric
Top achievements
Rank 1
answered on 21 Jun 2013, 12:22 PM
Hi Shinu,

I think it's not a correct solution.

When I move  RegisterOnSubmitStatement to !IsPostBack statement, first time does not fire, but second time does.

I guess it's just not register the script after first postback.

0
Accepted
Danail Vasilev
Telerik team
answered on 24 Jun 2013, 03:30 PM
Hi Eric,

ScriptManager.RegisterOnSubmitStatement method registers ECMAScript (JavaScript) code with the ScriptManager control for a control that is used with an UpdatePanel control that is executed when the form is submitted. This is explained in here.

Therefore you code can look like:
ASPX:
<asp:UpdatePanel ID="Updatepanel1" runat="server">
    <ContentTemplate>
        <telerik:RadButton ID="RadButton1" runat="server" Text="Text" OnClick="RadButton1_Click">
        </telerik:RadButton>
    </ContentTemplate>
</asp:UpdatePanel>
C#:
protected void Page_Load(object sender, EventArgs e)
{
    string script = "function f(){var button = $find(\'" + RadButton1.ClientID + "\');button.set_enabled(false); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
    ScriptManager.RegisterOnSubmitStatement(this, this.GetType(), "Onsubmit1", script);
}
 
protected void RadButton1_Click(object sender, EventArgs e)
{
    RadButton1.Text = "Click";
}
Note that I have used sys.application.load event, in order to ensure that the event is raised after all the scripts have been loaded on the page. Note also that the code will be executed only once and then removed, otherwise it will be called after every Ajax request.

More information on loading scripts from the code behind is available in Opening from the Server and Executing JavaScript function from server-side code help articles.


Regards,
Danail Vasilev
Telerik
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 the blog feed now.
0
Eric
Top achievements
Rank 1
answered on 25 Jun 2013, 01:55 AM
Hi Danail,

It's works , thanks !
Tags
Button
Asked by
Eric
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Eric
Top achievements
Rank 1
Danail Vasilev
Telerik team
Share this question
or