我的ASP.net页面有点问题.如果用户双击"提交"按钮,它将两次写入数据库(即在图像按钮上执行两次'onclick'方法)
如何使用,如果用户点击图像按钮,只是图像按钮被禁用?
我试过了:
<asp:ImageButton
runat="server"
ID="VerifyStepContinue"
ImageUrl=image src
ToolTip="Go"
TabIndex="98"
CausesValidation="true"
OnClick="methodName"
OnClientClick="this.disabled = true;" />
Run Code Online (Sandbox Code Playgroud)
但是这个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';" />
Run Code Online (Sandbox Code Playgroud)
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
}
} …Run Code Online (Sandbox Code Playgroud)