我在一个页面中有三个更新面板。当我想提交第一个按钮时,只显示第一个更新面板的值,另一个更新面板的值不应该被接受。
在第二个更新面板中,当我点击第二个按钮时,只取第二个更新面板的值。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ThreeUpdatepanel.aspx.cs" Inherits="ThreeUpdatepanel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div><asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<br />
<asp:UpdatePanel ID="UpdatePanel3" runat="server" >
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:TextBox id="TextBox1" runat="server">
</asp:TextBox>
<asp:Button ID="UPD1" runat="server" Text="UPD1" onclick="UPD1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:TextBox id="TextBox2" runat="server">
</asp:TextBox>
<asp:Button ID="UPD2" runat="server" Text="UPD2" onclick="UPD2_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UPD1" EventName ="Click" />
<%--<asp:PostBackTrigger ControlID="UPD2" />--%>
</Triggers>
</asp:UpdatePanel>
</form>
</body>
</html>
后面的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ThreeUpdatepanel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
}
}
protected void UPD1_Click(object sender, EventArgs e)
{
// My question is that when i click this button then also collected the value of another UpdatePanel(UpdatePanel2) TextBox(TextBox2.Text)
//Expected Result is TextBox2 value should be blank when i submit this button.
//UpdatePanel1.Update();
string x = TextBox2.Text;
Label1.Text = "You select: " + TextBox1.Text + ' ' + TextBox2.Text;
}
protected void UPD2_Click(object sender, EventArgs e)
{
// My question is that when i click this button then also collected the value of another UpdatePanel(UpdatePanel1) TextBox(TextBox1.Text)
//Expected Result is TextBox1 value should be blank when i submit this button.
//UpdatePanel2.Update();
string xx = TextBox1.Text;
Label1.Text = "You select: " + TextBox2.Text + ' ' +TextBox1.Text;
}
}
两次更新消息都应该显示第三个更新面板的标签。
请给我一些想法或给出一些解决方案。