473,385 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calling javascript function in masterpage file using RegisterClientScript problem

111 100+
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
2 2201
acoder
16,027 Expert Mod 8TB
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
16,027 Expert Mod 8TB
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

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

Similar topics

7
by: walter | last post by:
Here is my case : I create a user control which contains One checkbox control to enable/disable the other two textbox control. I'm using server control instead of HTML control, and I don't want to...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
3
by: First Last | last post by:
Hi, Newbie question: Why use Page.ClientScript.RegisterClientScript* when we can just make a .js file and include a reference to it in the page? (i.e. <script src="myscript.js"...
8
by: BiffMaGriff | last post by:
Hello, I am using VS2005 to code webapps using C#. I am trying to call the javascript function alert() from my codebehind. I am using master pages and AJAX. My page structure is as follows: ...
0
by: Matthew Wells | last post by:
Hello, I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all the updates. I have an aspx page with javascript that works fine until I try to separate the script into a .js...
9
by: Matthew Wells | last post by:
OK, I've narrowed down the problem. This works when in the aspx page <script type="text/javascript" > function btnFirst_Click() { alert("Hello");...
2
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side...
1
by: greatvishal | last post by:
Hi, I have a page where I am trying to render a pdf file using response.contenttype = "application/pdf". when the page has rendered, I need to launch a javascript command to launch the window's...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.