我在页面loadevent中将一些数据绑定到gridview .....
并且gridview位于更新面板中..
我使用模板字段在gridview的每一行中都包含了一个按钮。
每件事情都运转正常,但是当我点击按钮时,我会将一个行内容分配给更新面板之外的标签......
但这不会发生......
Button内的Code Snippet工作正常!!!!!
因为它在使用更新面板之前工作正常........由于整个页面发布到服务器以避免这种情况我使用了更新面板..
但它引发了另一个问题..
任何建议我怎样才能解决这类问题!!!!!!!!!!!
提前感谢!!!!
答案 0 :(得分:0)
在UpdatePanel内生成回发时,默认情况下,只更新面板中的内容。这是UpdatePanel的魔力:)
您需要在网格所在的同一更新面板中包含要修改的标签,或者将它们包装在单独的UpdatePanel上,并在网格面板更新时更新它。
Here您有一个关于如何触发第二个更新面板更新的示例。
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected DateTime LastUpdate
{
get
{
return (DateTime)(ViewState["LastUpdate"] ?? DateTime.Now);
}
set
{
ViewState["LastUpdate"] = value;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (LastUpdate.AddSeconds(5.0) < DateTime.Now)
{
UpdatePanel1.Update();
LastUpdate = DateTime.Now;
}
}
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Button1);
if (!IsPostBack)
{
LastUpdate = DateTime.Now;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>UpdatePanelUpdateMode Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<asp:Panel ID="Panel1"
GroupingText="UpdatePanel1"
runat="server">
<asp:UpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
runat="server">
<ContentTemplate>
<p>
The content in this UpdatePanel only refreshes if five or more
seconds have passed since the last refresh and the button in
UpdatePanel2 was clicked. The time is checked
server-side and the UpdatePanel.Update() method is called. Last
updated: <strong>
<%= LastUpdate.ToString() %>
</strong>
</p>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Panel ID="Panel2"
GroupingText="UpdatePanel2"
runat="server">
<asp:UpdatePanel ID="UpdatePanel2"
runat="server">
<ContentTemplate>
<p>
This UpdatePanel always refreshes if the button is clicked.
Last updated: <strong>
<%= DateTime.Now.ToString() %>
</strong>
</p>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>