Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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

Posted (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 by legendgod
Posted
I think it works without </script>. Try it
Well... 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.
Posted
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?

Posted

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

"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

Posted

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.

"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

Posted
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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...