当我单击数据库中的保存按钮数据存储时。使用f5数据刷新时保存两次。 我使用了更新面板,页面response.redirect(“samepage.aspx”)但没有用 aspx代码
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AddCust.aspx.cs" Inherits="AddCust" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Main" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<div>
<asp:TextBox ID="txtCustomername" runat="server" >
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter The name" ControlToValidate="txtCustomername" ></asp:RequiredFieldValidator>
<asp:DropDownList ID="ddlcustomer" runat="server"
onselectedindexchanged="ddlcustomer_SelectedIndexChanged">
</asp:DropDownList>
</div>
aspx代码
asxcs代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using odonovanTableAdapters;
public partial class AddCust : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
customerdropdown();
}
码
public void ButtonSave_Click(object sender, EventArgs e)
{
// ButtonSave.Attributes.Add("onclick", "return validate()");
string name = txtCustomername.Text;
string company = txtCompany.Text;
if (company == "")
{
company = "0";
}
string address = txtaddress.Text;
if (address == "")
{
address = "0";
}
long phonenumber = Convert.ToInt64(txtPhonenumber.Text);
string otherdetails = txtOtherDetails.Text;
if (otherdetails == "")
{
otherdetails = "0";
}
码
tblCustomerdetailsTableAdapter tadaptor = new tblCustomerdetailsTableAdapter();
tadaptor.Insert(name, company, address, phonenumber, otherdetails);
// Response.Write("<script>alert('saved successfully')</script>");
}
码
protected void customerdropdown()
{
//fill broker ddl
ddlcustomer.DataSource = DropDowns.ddlcustomers();
ddlcustomer.DataValueField = "CustomerName";
ddlcustomer.DataTextField = "CustomerName";
ddlcustomer.DataBind();
ddlcustomer.Items.Insert(0, "-- Select --");
}
码
protected void ddlcustomer_SelectedIndexChanged(object sender, EventArgs e)
{
string customername = ddlcustomer.SelectedValue;
spddlcustselectedvalueTableAdapter cadaptor = new spddlcustselectedvalueTableAdapter();
odonovan.spddlcustselectedvalueDataTable ctable = cadaptor.GetData(customername);
txtCustomername.Text = ctable.Rows[0][1].ToString();
}
}
答案 0 :(得分:0)
一旦成功保存记录,您就可以简单地将用户重定向到同一页面,以防止再次重复相同的操作(插入)。
在Querystring中传递一些令牌,以便您可以向用户显示成功消息。