我的 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;
实际上......这几乎可以工作。双击问题几乎是固定的(耶!)虽然图像仍然没有隐藏。