0

I have an ASP.net page that has a scriptmanager and an update panel on it. I need to call a javscript function from the codebehind on an server side event. i have tried using three methods to spit out javascript.

1) Clientscript.registerclientscriptblock()

2) Scriptmanager.registerClientscriptblock()

3) and also response.write()

None of the above seem to write to the page at all. what could be reason that all of the above methosd are failing?

what would be better method to call javascript now? my failed usage :

1) ClientScript.RegisterClientScriptBlock(Me.GetType(), "firstscript", "alert('test1')")

2) ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), "testscript", "alert('test2')", True)

3) Response.Write("<script language='Javascript' type='text/javascript'>alert('test 3')</script>")

I also used Response.Write("-test-") to see if it actaully writes to the page. but it doesn't. Any insight would be much helpful.

2 Answers2

0

In the Code Behind.

Create a ReadOnly Property on the page with your UpdatePanel.

Public Readonly Property xxx As UpdatePanel
Get
   Return upd1<--- this is your updatepanel object
end get
End Property

ScriptManager.RegisterStartupScript(xxx,me.gettype(),"Name", "Actual Javascript Here", true)

This should help you out

Shroeder
  • 115
  • 6
  • When using clientscript, make sure that you are referencing the parent page's ClientSript. Me.Page.ClientScript.RegisterclientscriptBlock("etc") – Shroeder Oct 01 '14 at 15:45
0

You could try RegisterStartupScript (here's a nice question about the differences between RegisterStartupScript and RegisterClientScriptBlock), but since your Response.Write doesn't work, something appears to be very wrong.
Are you sure you're testing your code correctly?

Community
  • 1
  • 1
Protector one
  • 6,926
  • 5
  • 62
  • 86