我弹出一个组合框的索引更改,我需要在后面的代码中得到确认框的结果:
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
这是我的功能:
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
请注意,我正在使用带有vb.net的asp.net
答案 0 :(得分:1)
以下链接显示了如何操作:Call VB method from JavaScript
它基本上说有两种方式,Ajax或Postback。这是回发方法:
aspx文件:
<script type="text/javascript">
<!--
function callServersideFunction()
{
var someValueToPass = 'Hello server';
__doPostBack('CustomPostBack', someValueToPass);
}
// -->
</script>
aspx.vb文件:
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