0

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

1 Answers1

0

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>
G3nt_M3caj
  • 2,497
  • 1
  • 14
  • 16