怎樣防止瀏覽器重新整理重複提交資料?

來源:互聯網
上載者:User

第一種方法:

不要用WEB控制項中的BUTTON用HTML中的BUTTON可以解決這個問題:
具體如下:
在:HTML中,定義這樣一個BUTTON
-------------------------
<input type="button" value="mybutton" onclick="this.disabled=true;" runat="server" id="mybutton" name="mybutton">
--------------------------------
然後在CODEBEHIND中,使用ServerClick事件,即:
    Private Sub mybutton_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles mybutton.ServerClick
.....
    End Sub
----------------------------------
注意,在CODEBEHIND中,還必須有以下這句定義按鈕的句子
   Protected WithEvents mybutton As System.Web.UI.HtmlControls.HtmlInputButton

下面是測試的代碼,你可以自己試試:

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此處放置初始化頁的使用者代碼

        If Not IsPostBack Then
            Dim conn As New SqlConnection("server=localhost;user id=sa;password=ycm119;database=pubs;")
            Dim dad As New SqlDataAdapter("Select  * from employee", conn)
            Dim dst As New DataSet
            dad.Fill(dst, "employee")
            DataGrid1.DataSource = dst.Tables("employee")
            DataGrid1.DataBind()
        End If

    End Sub

    Private Sub mybutton_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles mybutton.ServerClick
        DataGrid1.DataSource = ""
        DataGrid1.DataBind()
    End Sub
--------------------------------------------------------------------------------------------------------
http://community.csdn.net/Expert/topic/3344/3344371.xml?temp=.8338129#top

第二種方法:

在按鈕中寫
void Button1_Click(object sender, System.EventArgs e)
{
 // ....
 Response.Write("<script language='JavaScript'>alert('提交成功!');window.location='WebForm1.aspx';</script>");
}

原文地址:http://www.cnblogs.com/goody9807/archive/2005/02/04/101896.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.