I have the following Sub Routine in my vb.net project which runs fine, but I constantly get build warnings:
'Public Overridable Sub RegisterClientScriptBlock(key As String, script As String)' is obsolete: 'The recommended alternative is ClientScript.RegisterClientScriptBlock(Type type, string key, string script). visit http://go.microsoft.com/fwlink/?linkid=14202
I think it would be best if I used the correct method. I have followed the instructions here - http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx but it didn't make a great amount of sense. Any help would be appreciated.
Protected Sub DBC_MEMBER_IsActive_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DBC_MEMBER_IsActive.CheckedChanged
Dim showmessage As String = "Warning!\r\n \r\n Unticking this box will delete this Member from the Databse. \r\n \r\n If you are unsure, make sure the box remains ticked"
Dim alertScript As String = "<script language=JavaScript> "
alertScript += "alert('" & showmessage & "');"
alertScript += "</script" & "> "
If Not ClientScript.IsClientScriptBlockRegistered("alert") Then
Me.RegisterClientScriptBlock("alert", alertScript)
End If
End Sub
Try this:
If Not ClientScript.IsClientScriptBlockRegistered(GetType(YourPageClass), "alert") Then
ClientScript.RegisterClientScriptBlock(GetType(YourPageClass), "alert", alertScript)
End If
(Replace YourPageClass
by the name of your page's class).
The type and the key parameters are used to prevent registering the same script in the same page. The type parameter probably does not make sense when you register your script directly in the page (like you do). However, it allows for example to avoid potential conflicts between different custom controls which register a script with the same key parameter.
change Me.RegisterClientScriptBlock("alert", alertScript) to ClientScript.RegisterClientScriptBlock(TypeOf Me, "alert", alertScript)
I'm not sure if this is the right syntax in vb.net for "TypeOf Me". In C# it would look like this: ClientScript.RegisterClientScriptBlock(typeof(this), "alert", alertScript);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With