.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

ScriptManager.RegisterStartupScript crashes with AJAX

Posted By:      Posted Date: October 12, 2010    Points: 0   Category :ASP.Net
 

I have a user control that needs a javascript function so I put my JS code in a variable and used the ScriptManager.RegisterStartupScript in Page_PreRender of the control as follows

        StringBuilder jscode = new StringBuilder();
        jscode.Append(@"<script language=javascript>");
        jscode.AppendLine(@"function MyFunc(x) {  {alert('hi');  }");
        jscode.AppendLine(@"</script>");
 
        if (ScriptManager.GetCurrent(base.Page).IsInAsyncPostBack)
            ScriptManager.RegisterStartupScript(this, this.GetType(), "MyFuncJSKey", jscode.ToString(), false);



The problem is,  after the PreRender returns, the page crashes. I dont see any crash screen saying "Unhandled exception occurred"




View Complete Post


More Related Resource Links

ASP.NET: ScriptManager Enables AJAX In Your Web Apps

  

Learn how to use the ScriptManager control, which provides much of the magic behind ASP.NET AJAX.

Ben Rush

MSDN Magazine September 2007


ScriptManager.RegisterStartupScript is not working after post back

  
Hi,          I am registering javascript after page  post back using ScriptManager.RegisterStartupScript . it used to work previously. Ater there are some chagnes done in the project now it is not working. What might be the reason behind this. now i am unable to register the javascript after post back.Thanks and Regards,kiran

Scriptmanager.RegisterStartupScript Question

  
Hi,I registered a client script on a button click as ScriptManager.RegisterStartupScript(page, page.GetType(), "showFailure", "alert('123')", true);It shows me a javascript alert box '123'.Then I click another button and redirect to another page like Response.Redirect("SomeOtherPage.aspx");When I click back button (BROWSER BACK BUTTON) from SomeOtherPage.aspx then I again get an alert box 123.Reason: the script that I once registered is still on the page and is executed. I don't want the alert to appear again when I click browser back button.Regards,Muhammad Naveed Khan

Ajax 4.0 - ScriptManager ClientElementsToActivate Missing?

  

Hi there,

Various articles refer to the 4.0 ScriptManager (and Proxy) ClientElementsToActivate property.

However I can't find it.

Am I missing something really obvious?

I'm on VS 2010.

Cheers!


Modal Popup does not work with ScriptManager.RegisterStartupScript

  

Ok, here is my problem, I am using a masterpage that contains a javascript script (does not matter what it does) and on each page under that masterpage I am registering that script to run on page load. On the page under the masterpage, I am calling a modalpopupextender to display on a button click. Now, if I disable the register startupscript, the popup extender works fine, if I register the startup up script it does not


here is the script regster call

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "addscript", "miscscript()", True)

I have also tried this

Page.ClientScript.RegisterStartupScript(Me.GetType(), "addScript", "miscscript()", True)

I had this working fine using the second example when using .net 4 and the Ajax toolkit for 4 but I am now having to rollback to 3.5 due to a vendor requirement.

any help would be appreciated as I am completely stumped by this behavior.


Here is a little bit of extra info:

If I put the script in page and not in the masterpage and just run with a window.onload, both work fine, which is why I have figured that it must be something that I am doing with the registration of the script.

When I say it does not matter what I put as the sript, I mean, it can be a complex element property adjustment or a simple alert, n

ScriptManager.RegisterStartUpScript in another class??

  


I am trying to do a ajvascript alert message box using :

ScriptManager.RegisterStartupScript(this, this.GetType(), "err_msg", "file_error()", true);


This works perfectly when the line above is put in the Page_Load of the page.  However, when it is in another class and the Page_Load calls the object function, it does not work.  I've stepped through the code and its as if it just ignores it.  There is no error.


Can anyone tell me how to get it to work in another class file?

I am doing this:

Page page = HttpContext.Current.Handler as Page;

ScriptManager.RegisterStartupScript(page, page.GetType(), "err_msg", "waveform_file_error()", true);


but it does not work... thanks


ScriptManager.RegisterStartupScript and dynamic javascript issue

  

Hi all,

 

On my project I have a WebUserControl (.ascx) inside a page (the ascx is added statically on the HTML of the page, not dynamically).

 

On the ascx, on Page_Load, I need to generate a dynamic javascript function, and at the end register it (I do this everytime the page loads, being or not a PostBack).

 

Something like this is created:

 

private string GetScript()

{

return "function doSomething(){}";

}



 

And what I do after this on Page_Load is:

ScriptManager.RegisterStartupScript(this,this.GetType(),"DynamicJsFunction",GetScript(),true);

 

What I'm facing is this:

 

I'm able to get this working ok on my machine (XP SP2 Pro, IIS 5.1, Framework 3.5) and on a test server (Server 2003 Web Edition, IIS 6, Framework 3.5).

 

But on a high availability environment (production server and environment, Server 2003 Web Edition, IIS6, Framework 3.5, the machines have the same machine.config, the web sites have the same web.config file) the first time the page/webusercontrol shows up this works fine. If I make a postback, the javascript does not work. No error is thrown, no exception, just there is

Visual Studio 2010 SVP 1 AJAX ClientScripManager is defined in System.Web.UI but ScriptManager isn'

  

I developed a web app in VS 2010 using master pages. I am converting it to Ajax. Did an extensive amount of ClientScriptManager.RegisterHiddenField need to convert to ScriptManager.RegisterHiddenField.  However, the Class SctipManager does not appear in the object browser under System.Web.UI.  Am I missing an assembly?  I go into MSDN System.Web.UI namespace and it appears in the documentaion under that namespace.  Googling for information I keep running accross GAC something to do with Ajax extension.  Looked in windows/assemblies and did not see GAC. What is GAC?

Cannot locate ScriptManager in System.Web.UI framework 4.0.

My Configuragion:

Running in any cpu mode on a 64bit machine. I believe VS 2010 is running in x86 mode.


Visual Studio 2010 SVP 1 AJAX ClientScripManager is defined in System.Web.UI but ScriptManager isn'

  

I am converting a web app to ajax. Did an extensive amount of ClientScriptManager.RegisterHiddenField need to convert to ScriptManager.RegisterHiddenField.

Cannot locate ScriptManager in System.Web.UI framework 4.0. running in any cpu mode on a 64bit machine. I believe VS 2010 is running in x86 mode.

 


Terry Noren

Visual Studio 2010 SVP 1 AJAX ClientScripManager is defined in System.Web.UI but ScriptManager isn'

  

I am converting a web app to ajax.  Did an extensive amount of ClientScriptManager.RegisterHiddenField need to convert to ScriptManager.RegisterHiddenField.

Cannot locate ScriptManager in System.Web.UI framework 4.0. running in any cpu mode on a 64bit machine. I believe VS 2010 is running in x86 mode.

 


Microsoft AJAX CDN

  
Content delivery networks (CDNs) are composed of "edge cache" servers that are strategically placed around the world at key Internet network points. These "edge cache" servers can be used to cache and deliver all types of content - including images, videos, CSS and JavaScript files.

Using a CDN can significantly improve a website's end-user performance, since it enables browsers to more quickly retrieve and download content. For example, instead of having a browser request for an image traverse all the way across the Internet to your web server to download, a CDN can instead serve the request directly from a nearby "edge cache" server that might only be a single network hop away from your customer (making it return much faster - which makes your pages load quicker).

AJAX GridView Checkbox Select All in ASP.Net

  
In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

AJAX GridView Paging and Sorting using C# in ASP.Net

  
To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Paging Using Ajax in ASP.Net

  
To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

  
Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

Making Ajax Callbacks to the Server Using jQuery with ASP.NET

  
In the first part of this article series I introduced jQuery's functionality and how it provides a rich client side programming model. This time around I'll expand on these concepts and show you how you can use jQuery in combination with ASP.NET using it as an AJAX backend to retrieve data. I'll also discuss how you can create ASP.NET controls and otherwise interact with jQuery content from ASP.NET pages in WebForms.


jQuery is just a JavaScript library so it will work seamlessly with ASP.NET both from page code as well as through backend driven code using the Page.ClientScript object or ScriptManager. You can use jQuery on its own as a client side and Ajax library that communicates with ASP.NET or you can use jQuery in combination with ASP.NET AJAX. The two actually complement each other quite well as jQuery provides functionality that the ASP.NET AJAX library does not and vice versa. For the most part the interaction between the two libraries is trouble free except for a few very rare edge cases.

Building a grouping Grid with GridView and ASP.NET AJAX toolkit CollapsiblePanel

  
I've posted an update to this post to apply on demand loading of Details data using ASP.NET AJAX PageMethods. I'm demonstrating the usage if CollapsiblePanelExtender client events on the new post. Check it out.

I admit, Matt Berseth is really inspiring me! Few days ago I pass through 2 of his great posts:

.Surrounding your Data Table and Dialog Controls with ComponentArt Styled Panels
.Building a Grouping Grid with the ASP.NET 3.5 LinqDataSource and ListView Controls
The first one is pure design tips one which I used for making good presentation of my demo here. The 2nd post is actually the idea.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend