Formularen skulle ikke kunne sendes igen
Hej,Jeg har en simple formular med 6 felter, som sender data til en Access database. Jeg ville forhindre, at folk sender formularen igen.
Det handler om en konkurrence, og man skulle ikke kunne deltage mere end engang i konkurrencen.
Her er min aspx.cs filen:
----
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace SNSTips.tipskupon
{
/// <summary>
public class tipskupon : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox fNavn;
protected System.Web.UI.WebControls.TextBox fAdresse;
protected System.Web.UI.WebControls.TextBox fAlder;
protected System.Web.UI.WebControls.TextBox fTlf;
protected System.Web.UI.WebControls.DropDownList fSvar1;
protected System.Web.UI.WebControls.DropDownList fSvar2;
protected System.Web.UI.WebControls.Button btnSvar;
protected System.Web.UI.WebControls.Label lblFejl;
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
private void InitializeComponent()
{
this.btnSvar.Click += new System.EventHandler(this.btnSvar_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSvar_Click(object sender, System.EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
try
{
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + MapPath("../fpdb/Tips.mdb");
OleDbConnection myConnection = new OleDbConnection(connStr);
string strSQL = "INSERT INTO tips(Navn,Adresse,Alder,Tlf,Svar1,Svar2) Values (@fNavn,@fAdresse,@fAlder,@fTlf,@fSvar1,@fSvar2)";
OleDbCommand cmdInsert = new OleDbCommand( strSQL, myConnection );
cmdInsert.Parameters.Add( "@Navn", fNavn.Text );
cmdInsert.Parameters.Add( "@Adresse", fAdresse.Text );
cmdInsert.Parameters.Add( "@Alder", fAlder.Text );
cmdInsert.Parameters.Add( "@Tlf", fTlf.Text );
cmdInsert.Parameters.Add( "@Svar3", fSvar1.Text );
cmdInsert.Parameters.Add( "@Svar3", fSvar2.Text );
myConnection.Open();
cmdInsert.ExecuteNonQuery();
myConnection.Close();
}
catch (Exception errorVariable)
{
lblFejl.Text = "" + errorVariable.ToString();
}
finally
{
btnSvar.Visible = false;
}
}return;
}
}
}