Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HttpModules and Scripts

Status
Not open for further replies.

BoulderBum

Programmer
Jul 11, 2002
2,179
US
I have an HttpModule that I want to have run a script with the page gets delivered to the client, but for some reason it doesn't work.

Basically I have:

Code:
<html>
  <!-- blah blah blah -->
</html>

<!-- HttpModule inserted this on EndRequest -->
<script language='javascript'>
    alert('test');
</script>

Now, if I have the above as static text in my page, the script runs fine, but when the HttpModule dynamically writes it, nothing happens. The script doesn't run for some reason (though viewing the source makes it look identical)!

Does anyone know what I can do to acheive the effect I want across all pages?
 
How are you adding the sript to the page (e.g. are you using RegisterStartupScript or RegisterClientScriptBlock)?

Also, how are you calling the function from the actual page (e.g is it from the body onload event)?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
It's actually done through the HTTP Module, so all I have access to is the Application object and the Context/Response object through it (not the actual page). This is so I can write the script to each page served without having to manually add anything to all my pages.
 
In that case I would suggest an alternative approach by using page inheritance ie. each page inherits from a base class which in turn inherits System.Web.UI.Page.

This way you can directly add a client script block to each page.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Yeah, we have a base page for most of it all, but we really wanted a solution that would work for any page we had, even those outside the inheritace structure. :-( Oh well.

Thanks for your help, ca8msm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top