legendgod Posted May 30, 2004 Posted May 30, 2004 Because I want to apply some Javascript function I found on web, I use RegisterStartupScript. The following is place at the first sentence of Page_Load: Page.RegisterStartupScript("PopUpTextScript","<script language=javascript src='PopUpText.js'>")However, when the aspx is run, the <script language=....></script> tab is stand at the last position of <form></form> tab. It makes the Javascript do not run correctly. How to correct it? Thank you. Quote http://blog.legendgod.com
wessamzeidan Posted May 30, 2004 Posted May 30, 2004 Why don't you just place it in the aspx file where you want it?? Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
Rodenberg Posted May 30, 2004 Posted May 30, 2004 Don't place it in your page_load, overload the Render(HtmlTextWriter writer) method and place it before base.Render(writer); is called. Quote
bob01900 Posted May 30, 2004 Posted May 30, 2004 Have you tried putting it in Page_PreRender event instead of Page_Load? Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender 'Your code here End Sub Quote
legendgod Posted May 31, 2004 Author Posted May 31, 2004 (edited) Thanks Have you tried putting it in Page_PreRender event instead of Page_Load? Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender 'Your code here End Sub Thank you. When I add following, the javascript runs well.... but because lack of close tab: "</script>" All the html code after this tab become invalid and lost. However, when I type the code like that: Page.RegisterStartupScript("alertScript","<script language=javascript src=AlertScript.js></script>")It makes error... is it any escape character for the </script> ? Edited May 31, 2004 by legendgod Quote http://blog.legendgod.com
wessamzeidan Posted May 31, 2004 Posted May 31, 2004 I think it works without </script>. Try it Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
legendgod Posted June 1, 2004 Author Posted June 1, 2004 I think it works without </script>. Try itWell... I tried and success. However, when the code come to client side, I left a open tab: <script language=.....> towards the code. Therefore all the HTML code after the open tab lost their function. They cannot be seen in Internet explorer. Quote http://blog.legendgod.com
wessamzeidan Posted June 1, 2004 Posted June 1, 2004 try this <script language=javascript src=AlertScript.js /> Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
legendgod Posted June 2, 2004 Author Posted June 2, 2004 Have you tried putting it in Page_PreRender event instead of Page_Load? Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender 'Your code here End Sub Can I ask how should I rewrite the part "MyBase"? What is it define as? Quote http://blog.legendgod.com
Arch4ngel Posted June 2, 2004 Posted June 2, 2004 Page.RegisterStartupScript("alertScript",@"<script language=javascript src=AlertScript.js></script>") Do you see the @ ? it will permit you to go throught this one. Tell me if it work Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Arch4ngel Posted June 2, 2004 Posted June 2, 2004 As a supp. note... This would probably not work with old Netscape Browser. I know there's few that use it... but it's only to tell you. My company use Netscape 4.75 as a default browser for the WHOLE company. And it's not a small company... there's about 30,000 employee. So no need to tell you that, us... programmer... we can't get things to work properly 100% of the time. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
bob01900 Posted June 2, 2004 Posted June 2, 2004 Can I ask how should I rewrite the part "MyBase"? What is it define as? MyBase refers to the base class that your class/form inhereted from. ie. In your code, there should be something similar to the follwoing (somewhere at the top): Public Class WebForm1 Inherits System.Web.UI.Page ... And PreRender is an event inhereted from the Page class. I am not sure what you meant by "rewrite", you mean override functions or?? As for "</script>", I think you need it, or use what wessamzeidan suggested, close it with "/>". But I have no idea why "</script>" would fail. What kind of error are you getting? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.