1

i have a pop up on the index change of a combo box and i need to get the result of the confirm box in the code behind:

Protected Sub service_list_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles service_list.SelectedIndexChanged  

Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "confirm", x.javaMsg("Do you
want to choose a date?"), True)

If user clicks ok 
GridView1.DataSource = x.selectCNT(service_list.SelectedValue)
GridView1.DataBind()
End Sub

this is my function:

Public Function javaMsg(ByVal message As String) As String

    Dim sb As New System.Text.StringBuilder()
    sb.Append("window.onload=function(){")
    sb.Append("confirm('")
    sb.Append(message)
    sb.Append("')};")
    Return sb.ToString()

End Function

note that i'm using asp.net with vb.net

4

1 回答 1

1

Here is a link that shows how to do it: Call VB method from JavaScript

It basically says there are 2 ways, Ajax or Postback. Here is the postback method:

aspx file:

<script type="text/javascript">
 <!--
 function callServersideFunction()
 {
  var someValueToPass = 'Hello server';

 __doPostBack('CustomPostBack', someValueToPass);
 }
 // -->
 </script>

aspx.vb file:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  ' Insure that the __doPostBack() JavaScript method is created...
  Me.ClientScript.GetPostBackEventReference(Me, String.Empty)


 If Me.IsPostBack Then
   Dim eventTarget As String
   Dim eventArgument As String

  If ( (Me.Request("__EVENTTARGET") Is Nothing)
    eventTarget = String.Empty
   Else
    eventTarget = Me.Request("__EVENTTARGET"))
   If ( (Me.Request("__EVENTARGUMENT") Is Nothing)
    eventArgument = String.Empty
   Else
    eventArgument = Me.Request("__EVENTARGUMENT"))

  If eventTarget = "CustomPostBack" Then
    Dim valuePassed As String = eventArgument
    ' Call your VB method here...
   End If
  End If
 End Sub
于 2013-10-01T14:37:24.040 回答