【发布时间】:2009-09-30 13:54:11
【问题描述】:
我的 ASP.net 页面有一点问题。如果用户双击“提交”按钮,它将两次写入数据库(即对图像按钮执行两次“onclick”方法)
我怎样才能使如果用户点击图像按钮,只有图像按钮被禁用?
我试过了:
<asp:ImageButton
runat="server"
ID="VerifyStepContinue"
ImageUrl=image src
ToolTip="Go"
TabIndex="98"
CausesValidation="true"
OnClick="methodName"
OnClientClick="this.disabled = true;" />
但是这个 OnClientClick 属性完全阻止了页面的提交!有什么帮助吗?
抱歉,是的,我确实有验证控件...因此出现了棘手的问题。
目前仍在处理这个问题:
ASP 代码:
<asp:TextBox ID="hidToken" runat="server" Visible="False" Enabled="False"></asp:TextBox>
...
<asp:ImageButton runat="server" ID="InputStepContinue" Name="InputStepContinue" ImageUrl="imagesrc" ToolTip="Go" TabIndex="98" CausesValidation="true" OnClick="SubmitMethod" OnClientClick="document.getElementById('InputStepContinue').style.visibility='hidden';" />
C#代码:
private Random
random = new Random();
protected void Page_Load(object sender, EventArgs e)
{
//Use a Token to make sure it has only been clicked once.
if (Page.IsPostBack)
{
if (double.Parse(hidToken.Text) == ((double)Session["NextToken"]))
{
InputMethod();
}
else
{
// double click
}
}
double next = random.Next();
hidToken.Text = next + "";
Session["NextToken"] = next;
实际上……这几乎可行。双击问题几乎已解决(耶!)但图像仍然没有隐藏。
【问题讨论】:
标签: c# asp.net javascript onclick double-click