473,654 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ScriptManager in MasterPage

krungkrung
18 New Member
Hi all,

Can somebody help me figure out whats wrong with my program?

I created a site with the use of MasterPage..and with a plan of utilizing and abusing the capabilities of AJAX, I added the ScriptManager to create PageMethods.

Here's what I did:

1. I added the "ScriptMana ger" and the "JavaScript that calls the page method" in MasterPage...wi th Javascript inside the <body> tag and ScriptManager inside the <form> tag.

2. In the "Child Form", I created a HTML image component, and in the OnClick event it calls the JavaScript function which calls the PageMethod.


When I run the page it doesnt display any errors at all, but everytime I click the image component(which triggers the javascript func)..it displays "Error on page" at the bottom left side of the page and the desired output don't display.

You might be thinking that the error could be on the code(which probably true), but I tried the same code without using a MasterPage and it works without any error.

Any suggestion and advice will be very much appreciated. Thanks.
Jun 30 '09 #1
16 11611
Frinavale
9,735 Recognized Expert Moderator Expert
It is very likely that this is a JavScript error.
You could use IE8 or FireFox's FireBug tool to debug the error.

-Frinny
Jun 30 '09 #2
krungkrung
18 New Member
Hi Frinny!

Thanks for the reply.

Yeah I agree with you that it is very likely a JavaScript error. But why is it that, when I run the page in a single page(without using the MasterPage) and using the same JavaScript function, It executes smoothly? Isn't the error also something to do with 'ScriptManager' being placed in the MasterPage or something to that effect?

Btw, I placed the PageMethods inside a Base Class which inherits the System.Web.UI.P age and all pages inherits that Base Class. (I did this as it was mentioned in the other forum that PageMethods should be placed inside a BaseClass when using MasterPage)

Thanks.
Jul 1 '09 #3
sudevg
1 New Member
Hi krungkrung,

Can you pl tell that where the "JavaScript " function is written?

If the javascript function is written within UPDATEPANEL then there is a chance that script manager has discarded that function while rendering the page to browser. So I'd suggest to keep the function in separate file and register script file from the code behind.

Hope it helps,

Sudev Gandhi
Jul 1 '09 #4
Frinavale
9,735 Recognized Expert Moderator Expert
Sudev could be right...

You may need to register your JavaScript function with the ScriptManager.. .

We won't know until you share with us the error details that FireBug or IE8 tells you and give us more details on where/how you are defining your JS.

:)

-Frinny
Jul 1 '09 #5
krungkrung
18 New Member
hi Frinny and sudevg!

thanks for your generous reply.

sorry i forgot to post quickly, but i already figured out the problem.

the problem was just the control id being passed to the function. i found out that asp.net(correct me if am wrong) generates control id automatically, of every control within a page upon processing. eg, txtTextInput component would generate something like ctrl001_xxxxx_t xtTextinput control id. So if I pass the "txtTextInp ut", which is the control's name, to the function, the javascript's document.getEle mentById('txtTe xtInput') will return nothing since "txtTextInp ut" is not considered or identified as a control id of any control found within the page.

so here's what i did..though i think its kinda ugly but its the simplest way i could think for the mean time(if you have any idea i would be more than grateful if you share it to me)...from the code behind I pass the control's client Id to java script function...like , "txtTextinput.C lientID"...and that's it. as simple as that and my whole day was even brighter when I made it run after a couple of hours thinking what should be the problem of the program when I know I coded it correctly....ch eers!
Jul 3 '09 #6
Frinavale
9,735 Recognized Expert Moderator Expert
The "control id" is accessible in your .NET code using the ClientID property of ASP.NET controls.

There are a few things that I can add to this.

First of all, if your element is calling a JavaScript method that does something to that element, you can access that element by referring to "this" in JavaScript.

For example, the following TextBox calls the JavaScript method "toUpper()" which changes the text entered into upper case. Note how I'm passing "this" as the parameter..."th is" refers to the TextBox element (for simplicity sake I'm using pure HTML instead of asp for this example):
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.   <script type="text/javascript>
  4.     function toUpper(element){
  5.        element.value=element.value.toUpperCase();    
  6.     }
  7.   </script>
  8.   Enter some text: <input type="text" id="myTextBox" onkeyup="toUpper(this);" />
  9. </body>
  10. </html>
You can do the same thing with ASP elements....jus t pass the JavaScript function "this" and you'll have a reference to the element in your JavaScript.

If the JavaScript method does not modify the element that is calling it then you'll have to change things around a bit. Sometimes, if you don't want to pass the ClientID of the asp.net control into the method, you can dynamically print the ClientID directly into the JavaScript by calling the Response.Write( ) method using ASP.

In your ASP page you would have something like this:
Expand|Select|Wrap|Line Numbers
  1.   Enter some text: <asp:TextBox ID="myTextBox" runat="server" />
  2.  
  3.   <script type="text/javascript>
  4.     function toUpper(){
  5.       var element = $get('<%= myTextBox.ClientID %>');
  6.  
  7.       //The $get method is a method made available to us in the Ajax.NET
  8.       //framework. The Ajax.NET Framework is included with the page when
  9.       //you add a ScriptManager to the page. Since you have a ScriptManager
  10.      //on the page, you have access to this method. It is a short hand for
  11.      //javascript: document.getElementById() method. The following
  12.      //would accomplish the same thing:
  13.       //var element = document.getElementById('<%= myTextBox.ClientID %>');
  14.  
  15.        element.value=element.value.toUpperCase();    
  16.     }
  17.   </script>
Where in your .NET code you set the "onkeyup" for the myTextBox element.

Please note that <%= %> is class asp short hand for calling the Response.Write method. This will write the ClientID directly into the page so that you don't have to pass anything to the method.

This is only possible if your ASP element is on the same page as the JavaScript that it uses. If it's not on the same page then it's easier to just pass the element to the function.


-Frinny
Jul 3 '09 #7
krungkrung
18 New Member
Hi Frinny! Thanks for that very informative post. I really appreciate it. Im kinda..'wow!'.. and realized that I still have a lot of things to learn in asp.net....waaa yyy to go krungkrung..(", )


thanks..thanks. really.
Jul 6 '09 #8
krungkrung
18 New Member
Hi Frinny!

I just have a follow-up question...is it possible to pass a 'Page' as parameter from .Net procedure to a JavaScript function and return that passed 'Page' parameter to a VB.Net function...like :


Expand|Select|Wrap|Line Numbers
  1. Sub FromNet()
  2. Dim strTest As String = "<script language=javascript id='myClientScript'>ToJavaScript(" & MyPage & ");</script>"
  3.         Page.ClientScript.RegisterStartupScript(Me.GetType(), "testing", strTest )
  4. End Sub
  5.  
and the JavaScript would be:
Expand|Select|Wrap|Line Numbers
  1. function ToJavaScript(objPage)
  2. {
  3.     PageMethods.ReturnToNet(objPage);
  4. }
  5.  

Expand|Select|Wrap|Line Numbers
  1. Public Shared Sub ReturnToNet(ByVal myPage As Page)
  2.  
  3. call Kachurvahan(myPage )
  4.  
  5. End Sub
  6.  
Jul 6 '09 #9
Frinavale
9,735 Recognized Expert Moderator Expert
No this isn't possible.
The Page Object is a .NET Object....it doesn't exist in the browser.

What are you trying to do?
Jul 6 '09 #10

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

Similar topics

5
1736
by: Islamegy® | last post by:
In my project i have two master page which i change dynamic in runtime.. The first one with 1 ContentPanel "onepanel.master", the second with 2 contentPanel"twopanel.master".. but when i switch between them it don't work, if the default masterpage is "onepanel.master" and try to change it in runtime, ContentPanel2 which is exist in the loaded masterpage throw exception.. the same happen if the default is "twopanel.master" and switch it...
4
1616
by: cevans | last post by:
Is there a way to load a MasterPage programmatically? Not switch a page's masterpage but to create a MasterPage object that holds a given masterpage. So I know I can do: MasterPage master = new MasterPage(); But there is no way to do something like: MasterPage master = new MasterPage("~/default.master");
0
962
by: Jason Kester | last post by:
I've noticed some strange behavior with Atlas, and I'm wondering if anybody else is seeing this. Basically, from the moment I add a ScriptManager tag to one of my pages, any subsequent controls that I add will not show up in MyPage.aspx.designer.cs. It's like the presence of Atlas flips a switch somewhere in VS.NET and it stops tracking changes. I can reproduce this by creating a new document, adding a few HtmlInputText controls, then...
1
7549
by: =?Utf-8?B?TGFycnkgRXBu?= | last post by:
I have an app using Ajax. The scriptmanager is within the form that is within the master page. I also have web user controls that are doing partial rendering and are "borrowing" or "inheriting" the scriptmanager from the master page. Heck, when they're rendered, the scriptmanager is on all the pages and it works. However, in the VS2005 designer, I constantly see "Can't render image" errors, and it's nearly impossible to effectively use...
0
1444
by: Ryan | last post by:
Hi everyone, I have enabled my webparts site to use ajax by simply using updatepanels. This worked fine. Now I tried to enable drag and drop for the webparts so I added some stuff to the web config: http://blogs.neudesic.com/blogs/david_barkol/archive/2006/03/22/82.aspx I have a masterpage with no webpart stuff and child pages with all the webpartzones and the custom webpartmanager. I have tried putting the
0
1813
by: suganya | last post by:
Hi I have written the code for Atlas ModalPopup Control . The code is as follows <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
4
1723
by: WT | last post by:
Hello, How could we simulate the IsClientScriptBlocRegistered method of ClientScript when we use an update panel and the static ScriptManager ? Is this test already included in the ScriptManager.Registerxxx methods ? Regards CS
2
4883
by: abcd | last post by:
II have a asp.net application that using .NET framework 2.0. I use VS 2005. I opened VS 2008 and upgraded all the proejcts to .NET 3.5. My applicaiton has a code as below which is giving me error...any clues how to fix that... Parser Error Message: The base class includes the field 'ScriptManager', but its type (System.Web.UI.ScriptManager) is not compatible with the type of
2
1877
by: Ryan Liu | last post by:
Hi, Since ScriptManager need inside a server form, and web content page using MasterPage can not have another server form, so ajax can not be enabled (unless write own code) using ScriptManager? Any good way to solve this problem? In addition to MasterPage, is there server side include syntax as available in traditional asp page?
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8594
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7307
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.