0

我需要使用 ajax 进行部分渲染;我不知道出了什么问题。问题是什么?

我的代码:

ascx

<div id="temasatratar" onclick="__doPostBack('UpdatePanel1', '');"><h1>Temas a tratar</h1></div>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load">
    <ContentTemplate>
        <asp:Label runat="server" ID="Label1" />
    </ContentTemplate>
</asp:UpdatePanel>

ascx.cs

    protected void UpdatePanel1_Load(object sender, EventArgs e)
    {
        Random rnd = new Random();
        int number = rnd.Next(0, 99999);
        Label1.Text = "Best "+number;
    }

有什么建议吗?

我的应用程序:Sharepoint - Visual web part / C# / Asp.Net / Visual Studio

4

1 回答 1

2

我会使用一个不可见的假按钮作为触发器UpdatePanel

<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>

现在,当用户单击 div 时,此单击事件在异步回发中处理。

protected void fakeButton_Click(Object sender, EventArgs e)
{
    // you are in an asynchronous postback now
}
于 2013-07-03T15:40:52.217 回答