VB icon

Render Javascript from .NET Codebehind Pages

Email
Submitted on: 1/1/2015 1:52:00 AM
By: Tom Harris (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: VB.NET, ASP.NET
Views: 800
 
     Allows use of the RegisterClientScriptBlock and StringBuilder to create Javascript Functionality in your code behind pages. It isn't necessary to use StringBuilder but it is supposed to be very fast.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Render Javascript from .NET Codebehind Pages
// Description:Allows use of the RegisterClientScriptBlock and StringBuilder to create Javascript Functionality in your code behind pages. It isn't necessary to use StringBuilder but it is supposed to be very fast.
// By: Tom Harris (from psc cd)
//
// Inputs:Msg("Hello to all", Me.Page)
//
// Returns:Pops up a Javascript Window with the Text "Hello to All". You can add as many of the Window parameters as you like. ie..Height width, status, location etc. I kept it simple for you.
//
// Assumes:Javascript
//
// Side Effects:none as long as your browser supports the Javascript you are rendering
//**************************************

Shared Sub MsgBox(ByVal Message As String, ByVal SentPage As Page)
'Usage
'MsgBox("Hello to all", Me.Page)
Dim js_Script As New System.Text.StringBuilder("")
js_Script.Append("<Script LANGUAGE='JavaScript'>" & vbCrLf)
js_Script.Append("function popup() {")
js_Script.Append("msg=window.open("""",""msg"",""height=100,width=200,left=80,top=80"");")
js_Script.Append("msg.document.write(""<html><title>Message!</title>"");")
js_Script.Append("msg.document.write(""<body bgcolor='white' onblur=window.close()>"");")
js_Script.Append("msg.document.write(""<center><font face='arial'>" & Message & "</font></center>"");")
js_Script.Append("msg.document.write(""</body></html><p>"");")
js_Script.Append("};")
js_Script.Append("function returnnow() {;")
js_Script.Append("};")
js_Script.Append("</SCRIPT>")
js_Script.Append("</head>")
js_Script.Append("<body onload='popup();'>")
js_Script.Append("</body>")
SentPage.Page.RegisterClientScriptBlock("OpenWinScript", js_Script.ToString())
End Sub


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.