By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,702 Members | 1,771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,702 IT Pros & Developers. It's quick & easy.

Calling javascript function in masterpage file using RegisterClientScript problem

100+
P: 111
Hi all,

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



Expand|Select|Wrap|Line Numbers
  1. ScriptManager.RegisterClientScriptBlock(this, Page.GetType(), "Scroll", "ScrollToPosition();", true); 
  2.  
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.

Expand|Select|Wrap|Line Numbers
  1. <asp:ScriptManager ID="ScriptManager1" runat="server">
  2. </asp:ScriptManager>
  3.  
  4.  
  5. <asp:UpdatePanel ID="UpdatePanel1" runat="server">
  6.     <ContentTemplate>
  7.  
  8.                     <script language="javascript" type="text/javascript">
  9.                             function ScrollToPosition()
  10.                             {
  11.                                 var pnlErrorMessage = document.getElementById('ctl00_ContentPlaceHolder1_pnlErrorMessage');
  12.                                 var x = pnlErrorMessage.offsetLeft;
  13.                                 var y = pnlErrorMessage.offsetTop;
  14.  
  15.                                  alert("Script from master page");
  16.  
  17.  
  18.                                 window.scrollTo(x, y);
  19.                             }
  20.  
  21.                     </script>
  22.  
  23.                     <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
  24.                     </asp:ContentPlaceHolder>
  25.                 </ContentTemplate>
  26.             </asp:UpdatePanel>
  27.         </div>
Why this happens?



How to rectify it.



Thanks in advance.
May 27 '08 #1
Share this Question
Share on Google+
2 Replies


acoder
Expert Mod 15k+
P: 16,027
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.
May 27 '08 #2

acoder
Expert Mod 15k+
P: 16,027
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).
May 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.