我打算在更新传递地址链接按钮中放置保存和取消按钮。你对这个问题有什么建议?我如何解决这个问题?
<div class="form-group">
<label class="control-label col-lg-4">Delivery Address(Optional)</label>
<div class="col-lg-8">
<asp:LinkButton ID="UpdateAddress" runat="server" OnClick="UpdateAddress_Click" Text="Update Address" CssClass="btn btn-default" />
</div>
</div>
<div class="form-group" visible="false" runat="server" id="Street2">
<label class="control-label col-lg-4">Street</label>
<div class="col-lg-8">
<asp:TextBox ID="txtStreet2" runat="server" class="form-control" MaxLength="50" required />
</div>
</div>
<div class="form-group" visible="false" runat="server" id="Municapility2">
<label class="control-label col-lg-4">Municipality</label>
<div class="col-lg-8">
<asp:TextBox ID="txtMunicapility2" runat="server" class="form-control" MaxLength="100" required />
</div>
</div>
<div class="form-group" visible="false" runat="server" id="Region2">
<label class="control-label col-lg-4">Region</label>
<div class="col-lg-8">
<asp:DropDownList ID="ddlRegion2" OnSelectedIndexChanged="ddlRegion2_SelectedIndexChanged" runat="server" class="form-control" AutoPostBack="true" required />
</div>
</div>
<div class="form-group" visible="false" runat="server" id="City2">
<label class="control-label col-lg-4">City</label>
<div class="col-lg-8">
<asp:DropDownList ID="ddlCity2" runat="server" class="form-control" required />
</div>
</div>
<div class="col-lg-12">
<span class="pull-right">
<asp:Button ID="btnSave" class="btn btn-success" Text="Save" runat="server" />
<asp:Button ID="btnCancel" class="btn btn-danger" Text="Cancel" runat="server" />
</span>
</div>
传递LinkButton的C#代码添加
传递地址的LinkButton的C#代码
protected void UpdateAddress_Click(object sender, EventArgs e)
{
UpdateAddress.Visible = false;
Street2.Visible = true;
City2.Visible = true;
Region2.Visible = true;
Municapility2.Visible = true;
}
这是更新传递地址的保存和取消按钮的代码隐藏文件。
protected void btnSave_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Customers SET Street=@Street, Municipality=@Municipality, " +
"CityID=@CityID, RegionID=@RegionID, FROM Customers WHERE CustomerID=@CustomerID";
cmd.Parameters.AddWithValue("@Street", txtStreet.Text);
cmd.Parameters.AddWithValue("@Municipality", txtMunicipality.Text);
cmd.Parameters.AddWithValue("@CityID", ddlCity.SelectedValue);
cmd.Parameters.AddWithValue("@RegionID", ddlRegion.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("/Accounts/Checkout.aspx");
}
protected void btnCancel_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE Customers SET Street=@Street, Municipality=@Municipality, " +
"CityID=@CityID, RegionID=@RegionID, FROM Customers WHERE CustomerID=@CustomerID";
cmd.Parameters.AddWithValue("@Street", txtStreet.Text);
cmd.Parameters.AddWithValue("@Municipality", txtMunicipality.Text);
cmd.Parameters.AddWithValue("@CityID", ddlCity.SelectedValue);
cmd.Parameters.AddWithValue("@RegionID", ddlRegion.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("/Accounts/Checkout.aspx");
}
答案 0 :(得分:0)
要使用隐藏按钮启动,我认为您可以使用Visible =“false”
<asp:Button ID="btnSave" Visible="false" ... />
<asp:Button ID="btnCancel" Visible="false" ... />
单击“传递地址”按钮时,将其显示为:
protected void UpdateAddress_Click(object sender, EventArgs e)
{
btnSave.Visible = true;
btnCancel.Visible = true;
}
要在单击其他控件时隐藏它们:
protected void btnCancel_Click(object sender, EventArgs e)
{
btnSave.Visible = false;
btnCancel.Visible = false;
}