Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

RegisterStartupScript from ASP.NET Content Page

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
ChrisMDrew
Asked:
ChrisMDrew
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
Try using "Page.GetType()" rather than "this.GetType()"
0
 
jmnfCommented:
Re-load js script on child page, usually js from master pages do not work after postback
0
 
ChrisMDrewAuthor Commented:
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
 
ChrisMDrewAuthor Commented:
Sorry for those who suggested a solution - the problem is not actually as detailed but is an Ajax issue.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now