Solved

RegisterStartupScript from ASP.NET Content Page

Posted on 2011-02-23
4
516 Views
Last Modified: 2012-05-11
I have been re-writing a web application which used frames to use a master/content page architecture and have run into an odd problem.

Within a content page I have a form which the user complets and then clicks a 'Save' button.  This posts back to the server where some additional validation is performed and depending on the results I want to display a message to the user.  

The previous version had a JavaScript function 'ReportSaved' in the page which was called from the server side button handler using ClientScript.RegisterStartupScript which all worked perfectly.  This stopped working as soon as I started using master pages,

I have now simplified this within my button onclick handler to :-

const string alertScript = "alertSaveChanges";
if (!ClientScript.IsStartupScriptRegistered(this.GetType(), alertScript))
    ClientScript.RegisterStartupScript(this.GetType(), alertScript, "alert('help!!!');", true);

I can step through this and it all seems to work but my alert is not displayed.  Cionfused now so any help appreciated.

Also when I view the source after this call I cannot see the alert in the page source which I would expect to from memory of how it worked previously.

0
Comment
Question by:ChrisMDrew
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34965281
Try using "Page.GetType()" rather than "this.GetType()"
0
 
LVL 4

Expert Comment

by:jmnf
ID: 34965632
Re-load js script on child page, usually js from master pages do not work after postback
0
 

Accepted Solution

by:
ChrisMDrew earned 0 total points
ID: 34968637
My error - the problem is down to the fact that the containiong control (an Infragistics WebTab) has Ajax enabled.  This is preventing the script from being added as the page is not being posted back fully.
0
 

Author Closing Comment

by:ChrisMDrew
ID: 35005085
Sorry for those who suggested a solution - the problem is not actually as detailed but is an Ajax issue.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question