OnClick event not fire

5 posts, 1 answers
  1. Eric
    Eric avatar
    3 posts
    Member since:
    Apr 2013

    Posted 21 Jun 2013 Link to this post

    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>
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Jun 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eric
    Eric avatar
    3 posts
    Member since:
    Apr 2013

    Posted 21 Jun 2013 Link to this post

    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.

  5. Answer
    Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 24 Jun 2013 Link to this post

    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.
  6. Eric
    Eric avatar
    3 posts
    Member since:
    Apr 2013

    Posted 24 Jun 2013 Link to this post

    Hi Danail,

    It's works , thanks !
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017