我可以触发从下拉列表中选择一个更新面板中用户控件 [英] Can I trigger an Update Panel from a Drop Down list in a User Control
问题描述
我有两个下拉列表中的一个母版页的用户控件。当用户选择一个项目进行任何的DDL,我要加载的内容网页上的更新面板内的特定用户的控制。我无法弄清楚如何获得用户控件来触发更新面板。任何建议都非常AP preciated。
主
<%@注册SRC =toolbar.ascx变量名=工具栏标签preFIX =UC1%GT;
<头ID =头像1=服务器>
< /头>
<身体GT;
<表ID =form1的=服务器>
< DIV>
< ASP:ToolkitScriptManager ID =ToolkitScriptManager1=服务器>
< / ASP:ToolkitScriptManager>
< / DIV>
< UC1:工具栏ID =toolbar1=服务器/>
< ASP:的ContentPlaceHolder ID =ContentPlaceHolder1=服务器>
< / ASP:&的ContentPlaceHolder GT;
< /表及GT;
< /身体GT;
< / HTML>
用户控制
<%@控制语言=C#AutoEventWireup =真codeBehind =toolbar.ascx.cs继承=Blah.toolbar%GT;
< ASP:DropDownList的ID =ddlDesiredPage=服务器的AutoPostBack =真
的EnableViewState =真
onselectedindexchanged =goToSelectedPage>
< ASP:ListItem的值= - > DDL 1 LT; / ASP:ListItem的>
< / ASP:DropDownList的>
&安培; NBSP;
< ASP:DropDownList的ID =ddlDesiredPageSP=服务器的AutoPostBack =真
的EnableViewState =真
onselectedindexchanged =goToSelectedPage>
< ASP:ListItem的值= - > DDL 2'; / ASP:ListItem的>
< / ASP:DropDownList的>
内容页
< ASP:内容ID =内容1ContentPlaceHolderID =ContentPlaceHolder1=服务器>
< ASP:的UpdatePanel ID =UpdatePanel1=服务器的onload =UpdatePanel1_Load>
<&的ContentTemplate GT;
< ASP:占位符ID =PLACEHOLDER1=服务器>< / ASP:占位符>
< /&的ContentTemplate GT;
<&触发器GT;
?????????????????????????????????
< /触发器>
< / ASP:的UpdatePanel>
< / ASP:内容>
如果您想更新通过您所创建的用户控制面板,你可以尝试设置在UpdatePanel的的UpdateMode =条件
。然后,在你的用户控件的Click事件(或任何事件),有这样的事情:
的UpdatePanel mUpdatePanel = this.Page.Master.FindControl(upContent)作为UpdatePanel的;
如果(mUpdatePanel!= NULL)
{
mUpdatePanel.Update();
}
其他
{
//更新面板未找到
}
更新
既然你不能声明访问您的触发器,你可以从code-后面添加它们。在您的内容页面,添加如下内容:
AsyncPostBackTrigger triggerUserControl =新AsyncPostBackTrigger();
DropDownList的ucDDL = this.Page.Master.FindControl(ddlDesiredPage)作为DropDownList的;
triggerUserControl.ControlID = ucDDL.ID;
triggerUserControl.EventName =点击 UpdatePanel1.Triggers.Add(triggerUserControl);
执行相同的其他DropDownList的。我没有试过,但它似乎是合理的。
I have a user control in a master page with two drop down lists. When the user selects an item out of either ddl, I want to load a specific user control inside an update panel on the content page. I can't figure out how to get the user control to trigger the update panel. Any suggestions are very much appreciated.
Master
<%@ Register src="toolbar.ascx" tagname="toolbar" tagprefix="uc1" %>
<head id="Head1" runat="server">
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
</div>
<uc1:toolbar ID="toolbar1" runat="server" />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
User Control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="toolbar.ascx.cs" Inherits="Blah.toolbar" %>
<asp:DropDownList ID="ddlDesiredPage" runat="server" AutoPostBack="True"
EnableViewState="True"
onselectedindexchanged="goToSelectedPage">
<asp:ListItem Value="-">DDL 1</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlDesiredPageSP" runat="server" AutoPostBack="True"
EnableViewState="True"
onselectedindexchanged="goToSelectedPage">
<asp:ListItem Value="-">DDL 2</asp:ListItem>
</asp:DropDownList>
Content Page
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" onload="UpdatePanel1_Load">
<ContentTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
<Triggers>
?????????????????????????????????
</Triggers>
</asp:UpdatePanel>
</asp:Content>
If you want to update the panel via the User Control you've created, you could try setting the UpdatePanel's UpdateMode = Conditional
. Then, in your User Control's click event (or whichever event), have something like this:
UpdatePanel mUpdatePanel = this.Page.Master.FindControl("upContent") as UpdatePanel;
if (mUpdatePanel != null)
{
mUpdatePanel.Update();
}
else
{
//update panel not found
}
UPDATE
Since you can't access your triggers declaratively, you could add them from the code-behind. On your content page, add something like this:
AsyncPostBackTrigger triggerUserControl = new AsyncPostBackTrigger();
DropDownList ucDDL = this.Page.Master.FindControl("ddlDesiredPage") as DropDownList;
triggerUserControl.ControlID = ucDDL.ID;
triggerUserControl.EventName = "Click";
UpdatePanel1.Triggers.Add(triggerUserControl);
Do the same for the other DropDownList. I haven't tried this, but it seems reasonable.
这篇关于我可以触发从下拉列表中选择一个更新面板中用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!