更新面板的UpdateMode [英] UpdateMode of update Panel

查看:124
本文介绍了更新面板的UpdateMode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过示例给出有关UpdateMode =条件更新面板的清晰思路吗?

Can any one give clear idea about the UpdateMode=conditional of update panel with an example?

推荐答案

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>UpdatePanel</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
        <triggers>
            <asp:AsyncPostBackTrigger controlid="UpdateButton2" eventname="Click" />
        </triggers>
            <contenttemplate>
                <asp:Label runat="server" id="DateTimeLabel1" />
                <asp:Button runat="server" id="UpdateButton1" onclick="UpdateButton_Click" text="Update" />               
            </contenttemplate>
        
        <asp:UpdatePanel runat="server" id="UpdatePanel1" updatemode="Conditional">           
            <contenttemplate>
                <asp:Label runat="server" id="DateTimeLabel2" />
                <asp:Button runat="server" id="UpdateButton2" onclick="UpdateButton_Click" text="Update" />
            </contenttemplate>
        
    </form>
</body>
</html>



这是背后的代码.只需将以下方法添加到文件中:



Here is the CodeBehind. Just add the following method to the file:

protected void UpdateButton_Click(object sender, EventArgs e)
{
    DateTimeLabel1.Text = DateTime.Now.ToString();
    DateTimeLabel2.Text = DateTime.Now.ToString();
}


报价:

您将注意到,第一个按钮仅更新第一个日期戳,而第二个按钮同时更新两个日期戳.为什么?我们已将面板设置为有条件地更新,这意味着仅当面板中的某些内容导致回发或触发了定义的触发器之一时,才更新面板的内容.如您所见,第一个UpdatePanel带有一个引用第二个按钮的触发器.这将确保即使使用其他UpdatePanel上的控件时,也会更新第一个面板. AsyncPostBackTrigger标记非常简单-它仅具有两个属性,即controlid,可以触发它的控件的引用和eventname(事件名称),后者告诉您哪种事件类型可以触发触发器.如果您希望无论如何都更新UpdatePanel的内容,可以将updatemode属性更改为Always.

You will notice that then first button updates only the first datestamp, while the second button updates both. Why? We have set the Panels to update conditionally, which means that their content is only updated if something insides them causes a postback, or if one of the defined triggers are fired. As you can see, the first UpdatePanel carries a trigger which references the second button. This will ensure that the first panel is updated even when a control on a different UpdatePanel is used. The AsyncPostBackTrigger tag is pretty simple - it only takes two attributes, the controlid, a reference to the control which can trigger it, and the eventname, which tells which eventtype can cause the trigger to fire. If you wish for the content of a UpdatePanel to be updated no matter what, you may change the updatemode property to Always.


这篇关于更新面板的UpdateMode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆