从菜单控件更改updatepanel内容 [英] changing updatepanel content from menu control

查看:77
本文介绍了从菜单控件更改updatepanel内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个菜单控件,由一个存储过程从数据库填充,

它只包含名称,我想当用户点击其中一个名称时,它得到的数据是与该名称相关但没有回帖,它会在屏幕中间的更新面板中显示。

hello , i have a menu control that populated from a database by a stored procedure ,
its contains only names , i want when a user click on one of the name , it get the data that associated with that name but without a post back , it get it in an update panel at the middle of the screen .

推荐答案

< asp:UpdatePanel> tag有两个子标签 - ContentTemplate和Triggers标签。 ContentTemplate标记是必需的,因为它保存了面板的内容。内容可以是您通常放在页面上的任何内容,从文字文本到Web控件。触发器标签允许您定义某些触发器,这些触发器将使面板更新其内容。以下示例将显示两个子标签的使用。



The <asp:UpdatePanel> tag has two childtags - the ContentTemplate and the Triggers tags. The ContentTemplate tag is required, since it holds the content of the panel. The content can be anything that you would normally put on your page, from literal text to web controls. The Triggers tag allows you to define certain triggers which will make the panel update it''s content. The following example will show the use of both childtags.

<%@ 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>
        <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>
        </asp:UpdatePanel>
    </form>
</body>
</html>





这是CodeBehind。只需将以下方法添加到文件中:





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();
}



那么,这个例子到底是什么?尝试运行它,然后单击两个按钮。您会注意到,然后第一个按钮仅更新第一个日期戳,而第二个按钮更新两个按钮。为什么?我们已将Panel设置为有条件更新,这意味着只有在内容导致回发或其中一个已定义的触发器被触发时,才会更新其内容。



如您所见,第一个UpdatePanel带有一个引用第二个按钮的触发器。这将确保即使使用不同UpdatePanel上的控件也会更新第一个面板。



AsyncPostBackTrigger标签非常简单 - 它只需要两个属性,controlid,一个可以触发它的控件的引用,以及eventname,它告诉哪个eventtype会导致触发器触发。如果您希望更新UpdatePanel的内容,无论如何,您可以将updatemode属性更改为Always。



一般情况下,您应该只有UpdatePanels区域,您希望进行部分更新。不要将整个页面包装在UpdatePanel中,也不要害怕使用多个面板,因为这样可以更好地控制哪些区域更新以及何时更新。


So, what''s this example all about? Try running it, and click the two buttons. 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.

In general, you should only have UpdatePanels areound areas where you wish to do partial updates. Don''t wrap your entire page within an UpdatePanel, and don''t be afraid to use several panels, since this will give you more control of which areas update and when they do it.


这篇关于从菜单控件更改updatepanel内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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