如何从引发整个页面回发停止的UpdatePanel?页面、UpdatePanel

2023-09-07 02:04:01 作者:烟熏妆の祸害

我使用.NET 3.5和社区服务器内建设2008页的框架。

在我试图让一个UpdatePanel工作的一个页面上。

我参加了一个样品直接从ASP.NET网站,而是当我尝试和执行职能的一些原因 - 的通过点击按钮更新一个UpdatePanel当前时间的时间的

下面是我:

 保护无效的button1_Click(对象发件人,EventArgs的)
{
    Label1.Text =面板刷新在+ DateTime.Now.ToString();
    Label2.Text =面板刷新在+ DateTime.Now.ToString();
}

< ASP:ScriptManager的ID =ScriptManager1=服务器/>

< ASP:UpdatePanel的ID =UpdatePanel1=服务器>
    <的ContentTemplate>
        <字段集>
            <传奇>的UpdatePanel< /传说>
            < ASP:标签ID =标签1=服务器文本=面板中创建。>< / ASP:标签>< BR />
            < ASP:按钮的ID =Button1的=服务器的OnClick =的button1_Click文本=按钮/>
        < /字段集>
    < /的ContentTemplate>
< / ASP:UpdatePanel的>
 
如何把整个网页截图

每当我按一下按钮,确保面板更新 - 但整个页面回!我可以看到整个页面闪烁。你到底我做错了?

这可能是重要的一件事 - 我是一个嵌套母版里面,不知道这是一个问题。或者可能有东西在我使用,导致所有事件回发?这个社区服务器架构

感谢

解决方案

你有没有尝试设置 Button1的 AsyncPostBackTrigger 在触发器部分中, ChildrenAsTriggers 属性设置为的UpdateMode 属性条件

 保护无效的button1_Click(对象发件人,EventArgs的)
{
    Label1.Text =面板刷新在+ DateTime.Now.ToString();
    UpdatePanel1.Update();
}


< ASP:ScriptManager的ID =ScriptManager1=服务器/>
< ASP:UpdatePanel的ID =UpdatePanel1=服务器ChildrenAsTriggers =真的UpdateMode =条件>
    <触发器>
        < ASP:AsyncPostBackTrigger控件ID =Button1的事件名称=点击/>
    < /触发器>
    <的ContentTemplate>
        <字段集>
            <传奇>的UpdatePanel< /传说>
            < ASP:标签ID =标签1=服务器文本=面板中创建。>< / ASP:标签>< BR />
            < ASP:按钮的ID =Button1的=服务器的OnClick =的button1_Click文本=按钮/>
        < /字段集>
    < /的ContentTemplate>
< / ASP:UpdatePanel的>
 

I am using .NET 3.5 and building pages inside of the Community Server 2008 framework.

On one of the pages I am trying to get an UpdatePanel working.

I took a sample straight from ASP.NET website, but for some reason when I try and perform the function - update a time in an UpdatePanel to current time by clicking a button.

Here is what I have:

protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = "Panel refreshed at " + DateTime.Now.ToString();
    Label2.Text = "Panel refreshed at " + DateTime.Now.ToString();
}

<asp:ScriptManager ID="ScriptManager1" runat="server"/>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <fieldset>
            <legend>UpdatePanel</legend>
            <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        </fieldset>
    </ContentTemplate>
</asp:UpdatePanel>

Whenever I click the button, sure the panel updates - but the whole page posts back! I can see the whole page flashing. What the heck am I doing wrong?

One thing that may be important - I am inside of a nested Masterpage, not sure if this is a problem. Or could there be something in this Community Server framework that I'm using that causes all events to postback?

Thanks

解决方案

Did you try setting Button1 as an AsyncPostBackTrigger in the Triggers section, set the ChildrenAsTriggers property to true and the UpdateMode property to Conditional

protected void Button1_Click(object sender, EventArgs e)
{    
    Label1.Text = "Panel refreshed at " + DateTime.Now.ToString();    
    UpdatePanel1.Update();
}    


<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <Triggers>        
        <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />    
    </Triggers>    
    <ContentTemplate>        
        <fieldset>            
            <legend>UpdatePanel</legend>            
            <asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />            
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />        
        </fieldset>    
    </ContentTemplate>
</asp:UpdatePanel>