保存ボタンをクリックすると、データベースにデータが保存されます。f5 データを使用して更新すると、2 回保存されます。更新パネル、ページ 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();
}
}