F
Fresno Bob
I have a page which is a master page. I want to trigger a Javascript
function in the onload event of the body. Simply attaching an onload event
to the body which points to javascript function causes a javascript error
(Object not found on line 0). I read that ASP.net does not like you doing it
this way so I was looking at the ClientScript.RegisterClientScriptBlock.
This doesn't write anything. I have tried putting it in the page load event
of the master page and main page. What am I doing wrong. And also how do I
get the the injected javascript to be called in the on load function of the
page?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim sb As New StringBuilder
sb.Append("<script language=""JavaScript"" type=""text/javascript"">" &
Environment.NewLine)
sb.Append("<!--" & Environment.NewLine)
sb.Append("alert('test')" & Environment.NewLine)
sb.Append(" -->" & Environment.NewLine)
sb.Append("</script>" & Environment.NewLine)
Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "OnLoad",
sb.ToString)
End Sub
function in the onload event of the body. Simply attaching an onload event
to the body which points to javascript function causes a javascript error
(Object not found on line 0). I read that ASP.net does not like you doing it
this way so I was looking at the ClientScript.RegisterClientScriptBlock.
This doesn't write anything. I have tried putting it in the page load event
of the master page and main page. What am I doing wrong. And also how do I
get the the injected javascript to be called in the on load function of the
page?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim sb As New StringBuilder
sb.Append("<script language=""JavaScript"" type=""text/javascript"">" &
Environment.NewLine)
sb.Append("<!--" & Environment.NewLine)
sb.Append("alert('test')" & Environment.NewLine)
sb.Append(" -->" & Environment.NewLine)
sb.Append("</script>" & Environment.NewLine)
Page.ClientScript.RegisterClientScriptBlock(GetType(Page), "OnLoad",
sb.ToString)
End Sub