如何在模块中使用clientscript

发布于 2025-01-30 13:55:32 字数 620 浏览 5 评论 0原文

我想在模块中使用clientscript编码,然后从页面调用它。 剂量有人知道吗?

模块A

Module A
 public class sample
    Public Shared page As New Page
    Public Shared ClientScript As ClientScriptManager = page.ClientScript
    Public Shared Sub test()
        ClientScript.RegisterClientScriptBlock(page.GetType(), "test", "alert('test')", True)
    End Sub
 end class
End Module

页面B

Public Class sanplepage
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call A.sample.test()
    end sub
end class

I want to use clientscript coding in module, then call it from a page.
dose anybody know about it?

module A

Module A
 public class sample
    Public Shared page As New Page
    Public Shared ClientScript As ClientScriptManager = page.ClientScript
    Public Shared Sub test()
        ClientScript.RegisterClientScriptBlock(page.GetType(), "test", "alert('test')", True)
    End Sub
 end class
End Module

page B

Public Class sanplepage
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Call A.sample.test()
    end sub
end class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぇ气 2025-02-06 13:55:32

从此开始:

模块:

Module Module1

    Public Sub initTest(ByVal callerPage As Page)
        Dim scriptBuilder As StringBuilder = New StringBuilder
        scriptBuilder.Append("<script type='text/javascript'> ")
        scriptBuilder.Append("function clickByModule(){alert('heyyyyyyy coso, ma come si legge il tuo nome???');} ")
        scriptBuilder.Append("</script> ")
        callerPage.ClientScript.RegisterClientScriptBlock(callerPage.GetType(), "test", scriptBuilder.ToString)
    End Sub

End Module

Web Form后端:

Public Class WebForm1
    Inherits System.Web.UI.Page

    Private Sub WebForm1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Module1.initTest(Me)
    End Sub

End Class

webform前端:

<form id="form1" runat="server">
    <div>
        <input type="button" value="Click Me" onclick="clickByModule();" />
    </div>
</form>

Start from this:

Module:

Module Module1

    Public Sub initTest(ByVal callerPage As Page)
        Dim scriptBuilder As StringBuilder = New StringBuilder
        scriptBuilder.Append("<script type='text/javascript'> ")
        scriptBuilder.Append("function clickByModule(){alert('heyyyyyyy coso, ma come si legge il tuo nome???');} ")
        scriptBuilder.Append("</script> ")
        callerPage.ClientScript.RegisterClientScriptBlock(callerPage.GetType(), "test", scriptBuilder.ToString)
    End Sub

End Module

WebForm back-end:

Public Class WebForm1
    Inherits System.Web.UI.Page

    Private Sub WebForm1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Module1.initTest(Me)
    End Sub

End Class

WebForm front-end:

<form id="form1" runat="server">
    <div>
        <input type="button" value="Click Me" onclick="clickByModule();" />
    </div>
</form>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文