views:

2666

answers:

1

I have a form default.aspx with a scriptmanager and webpart manager.

I have 4 webpart zones. One of the zones has a basic user control for its content. The user control has a button inside an update panel and I have the following on the click event for the button:

Protected Sub cmdMarkComplete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdMarkComplete.Click
         Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType, "mymsg",   "<script>alert('hello');</script>", True)
         UpdatePanel1.Update()
End Sub

Nothing happens, I dont even get any javascript error but the aync does cycle as I can changes label value (as test) etc. If I check the source markup after the click, 'hello' is not even there so its as if its not registering the script. It must be todo with the fact I have an user ctrl inside a webpart. Can anyone help?

Thanks in advance.

+1  A: 

Try using ScriptManager.RegisterStartupScript, this should provide better support, esp for scripts added in an update panel

http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx

Chris
Thanks for the comments. I was using Scrptmanager priar, but noticed that its been superceeded by ClientScript.Reg. However I couldnt get it to work so I went back to old ScriptManager.Reg.
JamesM
Hmmm, are you sure? The obsolete methods I know of are implemented on the page object, as far as I am aware the ScriptManager class (of which register is a static method) is current. Looking at MSDN documentation does not mention it is obsolete (as it does for the page methods).
Chris
It was when I was using ScriptMan. in IDE it underlined like it does and said use ClientScript. So I tried that at the time, however I agree with you this does/did seem a bit wierd. Also from what I read you can only use ScriptMan during partial postbacks to get stuff registered. All fun/Games Hey!
JamesM