Calling javascript function in masterpage file using RegisterClientScript problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baburk
    New Member
    • Oct 2006
    • 111

    Calling javascript function in masterpage file using RegisterClientScript problem

    Hi all,

    when I call the javascript method from code behind file of the same page it works fine.



    Code:
    ScriptManager.RegisterClientScriptBlock(this, Page.GetType(), "Scroll", "ScrollToPosition();", true);
    But when i put the JavaScript method in the masterpage, there the problem occurs.



    When I press the button1,

    It scrolls to the new position and shows the alert message Script from master page.

    When i press OK it returns back to the bottom ie. to the position of the button1



    The master page coding is like this.

    Code:
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    
    
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
    
                        <script language="javascript" type="text/javascript">
                                function ScrollToPosition()
                                {
                                    var pnlErrorMessage = document.getElementById('ctl00_ContentPlaceHolder1_pnlErrorMessage');
                                    var x = pnlErrorMessage.offsetLeft;
                                    var y = pnlErrorMessage.offsetTop;
    
                                     alert("Script from master page");
    
    
                                    window.scrollTo(x, y);
                                }
    
                        </script>
    
                        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                        </asp:ContentPlaceHolder>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
    Why this happens?



    How to rectify it.



    Thanks in advance.
    Last edited by acoder; May 27 '08, 11:18 AM. Reason: Added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    As a full member now, you should know that we expect your code to be posted in [CODE] tags (See How to Ask a Question).

    This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

    Please use the tags in future.

    MODERATOR.

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by baburk
      But when i put the JavaScript method in the masterpage, there the problem occurs. When I press the button1, It scrolls to the new position and shows the alert message Script from master page. When i press OK it returns back to the bottom ie. to the position of the button1
      Please show the client-side HTML/JavaScript code as it appears in your browser (View Source).

      Comment

      Working...