C# 为什么不使用UpdatePanel进行部分渲染?
我需要用ajax进行部分渲染;我不知道怎么了。有什么问题吗 我的代码: 户控件 有什么建议吗C# 为什么不使用UpdatePanel进行部分渲染?,c#,asp.net,updatepanel,C#,Asp.net,Updatepanel,我需要用ajax进行部分渲染;我不知道怎么了。有什么问题吗 我的代码: 户控件 有什么建议吗 我的应用程序:Sharepoint-Visual web部件/C#/Asp.Net/Visual Studio我会使用一个不可见的假按钮作为更新面板的触发器: <div id="temasatratar" onclick="__doPostBack('fakeButton', '');"><h1>Temas a tratar</h1></div> <
我的应用程序:Sharepoint-Visual web部件/C#/Asp.Net/Visual Studio我会使用一个不可见的假按钮作为
更新面板的触发器:
<div id="temasatratar" onclick="__doPostBack('fakeButton', '');"><h1>Temas a tratar</h1></div>
<asp:LinkButton ID="fakeButton" style="display:none" runat="server" Text="foo" OnClick="fakeButton_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load">
<ContentTemplate>
<asp:Label runat="server" ID="Label1" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="fakeButton" />
</Triggers>
</asp:UpdatePanel>
您想何时更新该标签?我想在客户端单击id为“Temasatar”的div时更新标签。错误消息:El tipo'System.Web.UI.UpdatePanel'no tiene ninguna propedad pública cuyo nombre sea'AsyncPostBackTrigger'。/System.Web.UI.UpdatePanel没有名为的公共属性AsyncPostBackTrigger@Darkering:我忘记了触发器
部分。编辑了我的答案。UpdatePanel1_Load?@Darking:只是每个控件(例如,页面加载
)都存在的事件,但与您在div上的单击事件无关。由于div位于UpdatePanel
之外,因此当它是服务器控件(如按钮
)时,它甚至不会导致更新。因此,您需要显式的AsyncPostBackTrigger
。首先:感谢您的回答!但是:页面会完全刷新。更改的代码是:
protected void UpdatePanel1_Load(object sender, EventArgs e)
{
Random rnd = new Random();
int number = rnd.Next(0, 99999);
Label1.Text = "Best "+number;
}
<div id="temasatratar" onclick="__doPostBack('fakeButton', '');"><h1>Temas a tratar</h1></div>
<asp:LinkButton ID="fakeButton" style="display:none" runat="server" Text="foo" OnClick="fakeButton_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load">
<ContentTemplate>
<asp:Label runat="server" ID="Label1" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="fakeButton" />
</Triggers>
</asp:UpdatePanel>
protected void fakeButton_Click(Object sender, EventArgs e)
{
// you are in an asynchronous postback now
}