use javascript through vb.net

2.3k Views Asked by At

i want to write message through ScriptManager.RegisterStartupScript method . but am getting error in this statement.

my code
-------
ScriptManager.RegisterStartupScript(Me, Me.GetType, "temp", ("<script language='javascript'>alert(' No data in the database  ');</script>")), False)


error(in particular position)
-----
 , False)   error   -   end of the statement expected


 scriptmanager     Error 'System.Web.UI.Page.Friend ReadOnly Property ScriptManager As System.Web.UI.IScriptManager' is not accessible in this context because it is 'Friend'.  

Help me to correct the problem. am new to javascript

3

There are 3 best solutions below

1
On

Strange message, can you try the following:

System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(@"<script language='javascript'>");
sb.Append(@"alert(' No data in the database  ');");
sb.Append(@"</script>");

If (Not ClientScript.IsStartupScriptRegistered("JSScript")) Then
        ClientScript.RegisterStartupScript(Me.GetType(), "JSScript", sb.ToString());
0
On

This works for me:

Dim js As String = "alert('TGIF!!.')"
ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType, "popup", js, True)
0
On

I know this is an old tread but thought i would mention that i had the same problem using code from a .net 3.5 in 2.0, So it is finding a different definition of ScriptManager that is not the same as what I needed.

Once i changed the project to 3.5 it worked fine.