English 中文(简体)
在点击后处理
原标题:Disabling button after click
Private Function StoreCouponCode() As String
        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString)
        Dim sql As New SqlCommand("", con)
        Dim sqlGetSlNo As New SqlCommand("SELECT MAX(SlNo) FROM Coupons WHERE CustID=" & Convert.ToInt16(HFCustID.Value) & " AND BusiID=" & Convert.ToInt16(HFBusiID.Value) & " AND OfferID=" & Convert.ToInt16(HFOfferID.Value), con)
        Dim sNo, UserID, couponCode, offerCheck As String
        Dim slNo As Int16

        Try
            UserID = getCurrentUserID()
            con.Open()
            sNo = Convert.ToString(sqlGetSlNo.ExecuteScalar)      fteches latest serial no for the coupon
            If sNo = "" Then
                slNo = 0
            Else
                slNo = Convert.ToInt16(sNo) + 1
            End If
            couponCode = MakeCouponCode(slNo)
            offerCheck = couponCode.Substring(13, 3)
            sql.CommandText = "INSERT INTO Coupons VALUES (" & _
                                  HFCustID.Value & "," & HFBusiID.Value & "," & HFOfferID.Value & ", " & _
                                  Today.Date & " ," & Convert.ToString(slNo) & "," & offerCheck & ", " & couponCode & " , " & _
                                  UserID & " ," & LblPayInAdv.Text & "," & LblPayLater.Text & ", " & Convert.ToString(Date.Now) & " )"
            sql.ExecuteNonQuery()
            con.Close()
        Catch ex As Exception
            couponCode = "N/A"
        Finally
            con.Dispose()
            sql.Dispose()
        End Try
        Return couponCode
    End Function





Protected Sub CmdGetCoupon_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles CmdGetCoupon.Click
        If User.Identity.Name = "" Then
            LblMessage.Text = "You need to login first!"
            Exit Sub
        End If
        Dim couponCode As String = StoreCouponCode()
        Response.Redirect("~/Coupon.aspx?CouponCode=" & couponCode, True)
    End Sub

用户点击<代码> CmdGetCoupon 有时需要调整方向。 CmdGetCoupon不止一次,导致从单一用户账户产生多重政变。

我愿发表一个信息,即“在你共同发誓时,请瓦伊特”,并解脱<代码>。 CmdGetCoupon 因此,用户不能多次点击......。 任何想法? 如何做到这一点?

问题回答

用javascript的话说,使用OnClientClick来说明一种功能,使形式要素无法使用。

// On button
... OnClientClick="DisableMe(this);" ...

// Javascript
function DisableMe(elem)
{
   elem.disabled = true;
   // more code to show message
}

在阁下的html方面,你必须在ClientClick财产中添加:

<asp:Button ID="CmdGetCoupon" runat="server" onClientClick="this.disabled=true;" />

Edit:
Since @Oded so accurately pointed out that my first answer does not address the display of a message, here are a couple of options.

<span id="PleaseWaitContainer"></span>
<asp:Button ID="CmdGetCoupon" runat="server" onClientClick="this.disabled=true;document.getElementById( PleaseWaitContainer ).innerText= Please Wait While Your Coupon Is Being Generated ;" />

Or

<asp:Button ID="CmdGetCoupon" runat="server" onClientClick="this.disabled=true;alert( Please wait while your coupon is being generated... ;" />

You can disable the button in the click handler, because you re going to redirect to another page, so don t care about any other logic. Otherwise, if you re performing any async operation, again, disable it as soon as you click it, and in the async callback handler depending on the logic either enable it back or handle it properly in other way.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签