Rad Button not working with onClientClicked

2 posts, 0 answers
  1. Danny
    Danny avatar
    21 posts
    Member since:
    Jan 2009

    Posted 05 Apr 2012 Link to this post

    I have an application with a signin page. On the signin page, I load Javascript to get the UTCOffset from the clients browser. 

    When I use the standard asp.net button it works fine, when I try to use the radbutton. The button basically does not work. Not only just the javascript appear not to fire. It appears the page is not reloaded after the postback.

     I was using the OnClientClickproperty, but that is not an option for the RadButton. I have tried OnClientClicked and OnClientClicking properties. 

                <script language="javascript" type="text/javascript">

                    //logic for this found  http://forums.asp.net/t/1064203.aspx?PageIndex=2
                    function GetClientUtcOffset(frm) {
                        var d = new Date();

                        appendParam('uDate', d.getTimezoneOffset(), frm);

                    function appendParam(pName, pVal, tForm) {
                        var n = document.createElement('input');
                        n.setAttribute('name', pName);
                        n.setAttribute('type', 'hidden');
                        n.setAttribute('value', pVal);

                        var f = document.getElementById(tForm);

                        if (!f) {
                            // When using single Form page or not specifying Form
                            f = document.forms[0];

                        // append the new Element to the Form!

            protected void Page_Load(object sender, EventArgs e)
                 btnSignin.OnClientClicked = "javascript:GetClientUtcOffset()";

            protected void btnSignin_Click(object sender, EventArgs e)
                String comparePassword = "";
                String firstName = "";
                Int32 userId = 0;

             //   Session["UtcOffsetMins"] = Server.HtmlDecode(Request["uDate"]).Split(',')[0];
              //  txtEmailAddress.Text = Server.HtmlDecode(Request["uDate"]).Split(',')[0];
                txtEmailAddress.Text = "hello"; // even this does not work when I register JS on Page Load. 

  2. Slav
    Slav avatar
    1351 posts

    Posted 09 Apr 2012 Link to this post

    Hi Danny,

    As you have already found out the RadButton control has two client-side events that are fired on a button click - OnClientClicking and OnClientClicked. The encountered problem is caused by the values, passed to these properties. If you want to set an event handler for these or any of the other client-side events, you should specify only the name of the handler function, as shown in this helps article.

    In case you want to pass parameters to the attached handler method, you can use the approaches, described in this Code Library article.

    Feel free to contact us again if you encounter more difficulties.

    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.
  3. DevCraft R3 2016 release webinar banner
Back to Top