2011-01-29 87 views
5

我在我的vb.net项目中的以下子例程运行良好,但我不断地得到建立警告:如何解决的RegisterClientScriptBlock是在Visual Studio过时警告

“公众可重写小组的RegisterClientScriptBlock(键字符串,脚本 As String)'已过时:'推荐的替代方法是 ClientScript.RegisterClientScriptBlock(Type type,string key,string script)。访问http://go.microsoft.com/fwlink/?linkid=14202

我认为这将是最好的,如果我使用正确的方法。我按照这里的说明 - http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx,但它没有很大的意义。任何帮助,将不胜感激。

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 

回答

4

试试这个:

If Not ClientScript.IsClientScriptBlockRegistered(GetType(YourPageClass), "alert") Then 
    ClientScript.RegisterClientScriptBlock(GetType(YourPageClass), "alert", alertScript) 
End If  

(由您的网页类的名称替换YourPageClass)。

类型关键参数用于防止在同一页面中注册相同的脚本。 类型参数在您直接在页面中注册脚本时可能没有意义(就像您一样)。但是,它允许例如避免不同的自定义控件之间的潜在冲突,这些冲突使用相同的密钥参数注册脚本。

+0

我设法让你的更新工作,但我不得不使用以下:如果不是ClientScript.IsClientScriptBlockRegistered(GetType(会员),“alert”)然后 ClientScript.RegisterClientScriptBlock(GetType(Member),“alert”,alertScript) End If – James 2011-01-29 21:45:36

1

变化Me.RegisterClientScriptBlock( “警报”,alertScript)到ClientScript.RegisterClientScriptBlock(typeof运算我, “警报”,alertScript)

我不知道这是在VB正确的语法。 “TypeOf Me”网。在C#中它看起来像这样: ClientScript.RegisterClientScriptBlock(typeof(this),“alert”,alertScript);

+0

嗨,我试过你的建议,但VB说'是'是需要的... – James 2011-01-29 21:40:25