哪种方法可以更好地防止刷新页面后将数据重新插入数据库?
我应该在每次插入一行时检查数据库还是使用 viewState 和会话更有效?
protected void Page_Load(object sender, EventArgs e)
{
/* check refresh */
if (IsPostBack == false)
{
Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
}
//rest of the codes
}
protected void Page_PreRender(object sender, EventArgs e)
{
// set both session and viewstate value equal
ViewState["CheckRefresh"] = Session["CheckRefresh"];
}
protected void btnSaveTazkera_Click(object sender, EventArgs e)
{
if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
{
//give a new value to session
Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
//rest of the code
}
tnx。