I don't completely follow though. Using your code snippet as an example for names, in my scenario:
lbtn would be a button in the *master* page and UpdatePanel1 would be an update panel in the *content* page.
It looks to me that your code creates a 'new' button and adds it to the content template of an update panel, both on the same page. Yes?? Doesn't seem to have anything to do with triggers..? or take into account master/content page?
My Scenario (with your control names):
I have a button in a *master* page, say 'lbtn', that button needs to be registered as a PostbackTrigger in an updatePanel, say 'UpdatePanel1', which is in a *content* page. 'UpdatePanel1' is in a *content* page. 'lbtn' is in a *master* page.
How can I do that? Or did you actually answer that and I'm just not understanding??
Could someone provide small example that answers this? it will be important to note what's in the *master* page, what's in the *content* page etc.. like if a code sample is provided, where would it be located? etc..
Thank you Song-Tian, that's exactly what I needed... I figured it was something like that but wasn't sure where the code parts should go, I tried basically the same thing before but it didn't work, the difference was you letting me know it needs to go in
Page_Init... thank you!
If you don't mind I have a quick follow up question related to this:
Is there any real advantage or disadvantage to using the FindControl() method compared to making certian controls accessible through properties on the master and content page classes? In other words, instead of FindControl(), in order for master page to
access controls in content page, and in order for content page to access controls in master page, any difference between just using findControl() or creating properties? For example:
// like your example, FindControl() is used (lbtn is in the master page):
protected void Page_init(object sender, EventArgs e)
{
Button btn = (Button)this.Form.Parent.FindControl("lbtn");
AsyncPostBackTrigger Trigger1 = new AsyncPostBackTrigger();
Trigger1.ControlID = btn.ID;
Trigger1.EventName = "Click";
UpdatePanel1.Triggers.Add(Trigger1);
}
// Then the other part of this, now that I've registered the postbackTrigger, in my button click event that
// saves some data to a database, this button click event is for a button in a master page, at the end
// of the procedure I need to refresh the gridview on the content page, so I can use
// FindControl() again like this:
// refresh gridview - ContentPlaceHolder_Main is contentPlaceHolder in masterpage
GridView TheGridView = (GridView) ContentPlaceHolder_Main.FindControl("Gridview_Customers");
TheGridView.DataBind()
This works, but again, I'm wondering about using properties rather than FindControl() method? I have a lot of scenarios where master page needs to access content page controls and content page needs to access master page controls so I was wondering if using
properties was better? faster?
your input on this would be greatly appreciated. Again, I know you *can* use properties, the real questions is should I? is it better? Better only under certian circumstances?
ok, thanks again... I hate to ask what seems like the same question again, but just to be clear, is it still ok to use FindControl() in a scenario like this:
modal form defined in master page, has say 8 to 16 input controls (textboxes, dropdowns, etc...). I need to popup that modal form *and* populate all those controls from an event triggered in the content page (a button click).
so that could be 8 to 16 FindControl() calls in a row in that one postback method (the button click)... Is using FindControl() still ok for that scenario?
thanks again, I really appreciate your help. If it's even ok for that many then I have my answer and that is what I will do. I was just wondering about creating properties specifically because I knew I would need to call FindControl() so many times one after
another, whereas if I created a property in the masterpage class to access each control it seemed like it would be more direct, and therefore faster *if* my scenario required too many FindControl() calls.
Still stick with findControl()? or use properties?
c0pe
Member
319 Points
435 Posts
how do I add trigger to update panel when the trigger control is in master page?
Apr 21, 2012 01:14 PM|LINK
Hello,
How do I add a trigger to an update panel when the trigger control is a button in the master page, and the update panel is in a content page?
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 23, 2012 09:19 AM|LINK
Hi,
You could dynamic add control as follow:
LinkButton lbtn = new LinkButton(); lbtn.Text = "LinkButton"; lbtn.ID = "lbtn1"; lbtn.Click += new EventHandler(lbtn1_Click); UpdatePanel1.ContentTemplateContainer.Controls.Add(lbtn);Feedback to us
Develop and promote your apps in Windows Store
c0pe
Member
319 Points
435 Posts
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 23, 2012 01:36 PM|LINK
Hello Song-Tian, thanks for the response.
I don't completely follow though. Using your code snippet as an example for names, in my scenario:
lbtn would be a button in the *master* page and UpdatePanel1 would be an update panel in the *content* page.
It looks to me that your code creates a 'new' button and adds it to the content template of an update panel, both on the same page. Yes?? Doesn't seem to have anything to do with triggers..? or take into account master/content page?
My Scenario (with your control names):
I have a button in a *master* page, say 'lbtn', that button needs to be registered as a PostbackTrigger in an updatePanel, say 'UpdatePanel1', which is in a *content* page. 'UpdatePanel1' is in a *content* page. 'lbtn' is in a *master* page.
How can I do that? Or did you actually answer that and I'm just not understanding??
Could someone provide small example that answers this? it will be important to note what's in the *master* page, what's in the *content* page etc.. like if a code sample is provided, where would it be located? etc..
Help would be much appreciated... Thanks!
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 24, 2012 03:59 AM|LINK
Hi,
Please refer to the follow example:
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage1.master" AutoEventWireup="true" CodeFile="dynamicaddtrigger.aspx.cs" Inherits="dynamicaddtrigger" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <br /> Out of updatepanel: <%=DateTime.Now %> <br /> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false"> <ContentTemplate> In Updatepanel: <%=DateTime.Now %> </ContentTemplate> <Triggers> </Triggers> </asp:UpdatePanel> </asp:Content>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class dynamicaddtrigger : System.Web.UI.Page { protected void Page_init(object sender, EventArgs e) { Button btn = (Button)this.Form.Parent.FindControl("lbtn"); AsyncPostBackTrigger Trigger1 = new AsyncPostBackTrigger(); Trigger1.ControlID = btn.ID; Trigger1.EventName = "Click"; UpdatePanel1.Triggers.Add(Trigger1); } protected void Page_Load(object sender, EventArgs e) { } }Feedback to us
Develop and promote your apps in Windows Store
c0pe
Member
319 Points
435 Posts
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 24, 2012 01:56 PM|LINK
Thank you Song-Tian, that's exactly what I needed... I figured it was something like that but wasn't sure where the code parts should go, I tried basically the same thing before but it didn't work, the difference was you letting me know it needs to go in Page_Init... thank you!
If you don't mind I have a quick follow up question related to this:
Is there any real advantage or disadvantage to using the FindControl() method compared to making certian controls accessible through properties on the master and content page classes? In other words, instead of FindControl(), in order for master page to access controls in content page, and in order for content page to access controls in master page, any difference between just using findControl() or creating properties? For example:
// like your example, FindControl() is used (lbtn is in the master page): protected void Page_init(object sender, EventArgs e) { Button btn = (Button)this.Form.Parent.FindControl("lbtn"); AsyncPostBackTrigger Trigger1 = new AsyncPostBackTrigger(); Trigger1.ControlID = btn.ID; Trigger1.EventName = "Click"; UpdatePanel1.Triggers.Add(Trigger1); } // Then the other part of this, now that I've registered the postbackTrigger, in my button click event that // saves some data to a database, this button click event is for a button in a master page, at the end // of the procedure I need to refresh the gridview on the content page, so I can use // FindControl() again like this: // refresh gridview - ContentPlaceHolder_Main is contentPlaceHolder in masterpage GridView TheGridView = (GridView) ContentPlaceHolder_Main.FindControl("Gridview_Customers"); TheGridView.DataBind()This works, but again, I'm wondering about using properties rather than FindControl() method? I have a lot of scenarios where master page needs to access content page controls and content page needs to access master page controls so I was wondering if using properties was better? faster?
your input on this would be greatly appreciated. Again, I know you *can* use properties, the real questions is should I? is it better? Better only under certian circumstances?
thanks again!
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 24, 2012 02:59 PM|LINK
Hi,
I think findcotrol performance is no problem. And I suggest you using that.
Feedback to us
Develop and promote your apps in Windows Store
c0pe
Member
319 Points
435 Posts
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 24, 2012 05:40 PM|LINK
ok, thanks again... I hate to ask what seems like the same question again, but just to be clear, is it still ok to use FindControl() in a scenario like this:
modal form defined in master page, has say 8 to 16 input controls (textboxes, dropdowns, etc...). I need to popup that modal form *and* populate all those controls from an event triggered in the content page (a button click).
so that could be 8 to 16 FindControl() calls in a row in that one postback method (the button click)... Is using FindControl() still ok for that scenario?
thanks again, I really appreciate your help. If it's even ok for that many then I have my answer and that is what I will do. I was just wondering about creating properties specifically because I knew I would need to call FindControl() so many times one after another, whereas if I created a property in the masterpage class to access each control it seemed like it would be more direct, and therefore faster *if* my scenario required too many FindControl() calls.
Still stick with findControl()? or use properties?
thanks again! Last question on this I promise :)
Song-Tian - ...
All-Star
43705 Points
4304 Posts
Microsoft
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 25, 2012 01:52 AM|LINK
Hi,
You could have a try. You could create new thread if you still confusion about that.
Feedback to us
Develop and promote your apps in Windows Store
c0pe
Member
319 Points
435 Posts
Re: how do I add trigger to update panel when the trigger control is in master page?
Apr 25, 2012 04:37 PM|LINK
ok, thanks for all the help. I appreciate it.