--------------------确认对话框--------------------------------------
前台:
<td> <asp:Button ID="btnOutPut" runat="server" Text="确认按钮" /></td>
<td style="visibility: collapse"><%-- collapseは必須、hiddenの場合エラーが起こる --%><asp:Button ID="btnHid" runat="server" OnClick="btnHid_Click" Width="1px" />
</td>
<asp:HiddenField ID="hid" runat="server" />
----------------------------------------------------------
后台:
' ConfirmボタンイベントDim js As String = String.Format("document.getElementById('{0}').value=confirm('确认信息?');document.getElementById('{1}').click();", hid.ClientID, btnHid.ClientID)
ClientScript.RegisterStartupScript(Me.GetType, "confirm", js, True)
'
Protected Sub btnHid_Click(sender As Object, e As EventArgs) Handles btnHid.Click
If hid.Value.ToLower() = "true" Then
'TODO...
Else
'TODO...
End If
End Sub
--------------------JS调用后台相关方法--------------------------------------
前台:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<script type="text/javascript">
function TestJs() {
//jsでセッションを読み込む
var id = '<%=Session("UserName")%>';
alert(id);
//jsでCSの変数を読み込む
var csValue = '<%=csValue%>';
alert(csValue);
//jsでCSの関数を読み込む
var par = "test value";
var getValue = '<%=getValue("' + par + '")%>';
alert(getValue);
}
</script>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="TestJs()" />
</div>
</form>
</body>
</html>
----------------------------------------------------------
后台:
Public csValue As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Session("UserName") = "hanhanhan"
csValue = "111111"
End Sub
Public Function getValue(ByVal par As String)
Return par
End Function