【发布时间】:2013-11-21 04:53:18
【问题描述】:
这是脚本,我想在之前使用按钮按钮的 clentclick 属性的代码中使用它 我想在不使用按钮的情况下使用此代码
<script type = "text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Do you want to save data?")) {
confirm_value.value = "Yes";
} else {
confirm_value.value = "No";
}
document.forms[0].appendChild(confirm_value);
}
</script>
<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
我还能做些什么来实现它对我来说是可行的
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
// TextBox1.Attributes.Add("OnClientClick", "Confirm()");
string confirmValue = Request.Form["confirm_value"];
if (confirmValue == "Yes")
{
//Your logic for OK button
}
else
{
//Your logic for cancel button
}
}
public void OnConfirm(object sender, EventArgs e)
{
}
【问题讨论】:
-
这里到底有什么问题?
-
文本框中的onclientclick相当于什么,不调用js代码不会运行
-
文本框没有点击事件,它们并非设计为按钮。您将需要某种方式通过 JavaScript 或通过按钮将表单提交回服务器。 msdn.microsoft.com/en-us/library/…
标签: c# javascript jquery asp.net .net