的RegisterClientScriptBlock我如何解决是在Visual Studio中过时的警告 [英] How do I fix RegisterClientScriptBlock is Obsolete warning in Visual Studio

查看:1397
本文介绍了的RegisterClientScriptBlock我如何解决是在Visual Studio中过时的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的vb.net项目中的以下子程序它运行很好,但我不断地得到建立警告:

公共可重写子的RegisterClientScriptBlock(键作为字符串,脚本
作为字符串)已过时:推荐的替代方案是
ClientScript.RegisterClientScriptBlock(类型类型,字符串键,字符串
脚本)。
的访问 http://go.microsoft.com/fwlink/?linkid = 14202

我想,如果我用正确的方法将是最好的。我在这里跟着指示 - 的http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx但它并没有弄懂大量。任何帮助将是AP preciated。

 保护小组DBC_MEMBER_IsActive_CheckedChanged(BYVAL发件人为对象,BYVAL E上System.EventArgs)把手DBC_MEMBER_IsActive.CheckedChanged
        昏暗showmessage的String =警告!\\ r \\ n \\ r \\ n,一是不要选中此复选框将从DATABSE删除该会员。\\ r \\ n \\ r \\ n如果不确定,确保选中保持打勾
        昏暗alertScript作为字符串=< SCRIPT LANGUAGE = JavaScript的>中
        alertScript + =警报('&放大器; showmessage&安培;');
        alertScript + =< / SCRIPT&放大器; >中        如果不ClientScript.IsClientScriptBlockRegistered(警告),然后
            Me.RegisterClientScriptBlock(警报,alertScript)
        万一
    结束小组


解决方案

试试这个:

 如果不ClientScript.IsClientScriptBlockRegistered(的GetType(YourPageClass),警报),然后
    ClientScript.RegisterClientScriptBlock(的GetType(YourPageClass),警戒,alertScript)
万一

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

键入的和的的参数用于prevent在同一个页面注册相同的脚本。在键入的参数可能没有当您直接在页面注册您的脚本(像你一样)才有意义。但是,它允许例如以避免注册的脚本具有相同的键不同的自定义控件之间的潜在冲突的参数。

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.

这篇关于的RegisterClientScriptBlock我如何解决是在Visual Studio中过时的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆