Stop RadWindow postback after javascript event

4 posts, 1 answers
  1. Gary
    Gary avatar
    20 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2013 Link to this post

    I have a radwindow in which I have a button execute some javascript which manipulates the css classes of some elements. I see that this works, but then the content posts back and refreshes and the changes that the javascript just made get wiped out. How can I stop the radwindow from reloading after I execute a javascript function?

    Here is the code for the button on the page loaded in the RadWindow:
    <div style="padding:10px 10px 10px 10px; position:fixed; background-color:white; width:100%; z-index:100; height:15px;">
        <table>
                 <tr>
                    <td>
                        <button id="btnModify" onclick="ShowModify(); return false;">Modify</button>
                    </td>
                 </tr>
      </table>
    </div>


    And here's the javascript I have in the RadWindow:
    function ShowModify()
    {
            var elems = document.getElementsByTagName("span");
            for (i in elems)
            {
                 if (elems[i].className == "modifyField")
                 {
                      elems[i].className = "modifyFieldVisible";
                 }
             }
             return false;
    }
  2. Answer
    Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 08 Aug 2013 Link to this post

    Hi Gary,

    Does this work when placed directly on the page outside of a RadWIndow? I am asking because RadWindow does not modify its content, so it cannot generate a postback by itself. The most likely reason I can see for the behavior you describe is a JS error in the custom code that you are using. It is also entirely possible that something else on the page is causing the postback, e.g. a timer.


    Regards,
    Marin Bratanov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gary
    Gary avatar
    20 posts
    Member since:
    Oct 2012

    Posted 08 Aug 2013 Link to this post

    Marin,
    Good suggestion! I did exactly that and found that it was a javascript exception that was thrown that was causing the page to postback.

    Thanks!
  5. Anjali
    Anjali avatar
    2 posts
    Member since:
    Aug 2013

    Posted 09 Aug 2013 Link to this post

    Hello Gary

    I am completely satisfied with Marin Bratanov's answer. You must check for your custom code  applied.

    PHP Development India
Back to Top