Page view counter

Can an Update Panel trigger on a control in a different Content area?

Last post 10-14-2008 3:55 AM by naveen.gummudu. 12 replies.

Sort Posts:

  • Can an Update Panel trigger on a control in a different Content area?

    11-07-2006, 1:21 PM
    • Loading...
    • ormico
    • Joined on 05-19-2005, 5:33 PM
    • Macon, GA
    • Posts 6
    I have a web site with a master page that has 2 content areas.
     
    In my aspx page, I have some controls in an UpdatePanel. In the 2nd content area I have a button that takes some values and binds a gridview in the update panel that is in the 1st content area.
     
    This works if I leave the update panels off, but it posts back. If I add the update panel and set a trigger on the button click event I get the error "A control with ID 'btSearch' could not be found for the trigger in UpdatePanel 'UpdatePanel2'." If I move the button into the 1st content area, then it works. However, I need to have the button in the 2nd content area.
     
    It seems that the update panel can't find the button by ID when it is in a seperate content area. 
     
    I added the following code to my codebehind, but I get the error "A control with ID 'ctl00_cpContext_btSearch' could not be found for the trigger in UpdatePanel 'UpdatePanel2'."
     

       15 protected void Page_Load(object sender, EventArgs e)

       16 {

       17     foreach(UpdatePanelTrigger t in UpdatePanel2.Triggers)

       18     {

       19         AsyncPostBackTrigger apt = t as AsyncPostBackTrigger;

       20         if(apt != null && apt.ControlID == "btSearch")

       21         {

       22             apt.ControlID = btSearch.ClientID;

       23             break;

       24         }

       25     }       

       26 }

     

    I stepped through the code and it correctly finds the trigger and replaces the ID, but the update panel is still complaining that it can't find the control using the new ID.

     

    ControlID is a string. I was assuming that since "btSearch" didn't work that btSearch.ClientID would, but it didn't.

     
     
    Does anyone have an idea on how to fix this? Or am I doing something wrong?
     
     
    -Zack Moore
    http://ZacksFiasco.com/
  • Re: Can an Update Panel trigger on a control in a different Content area?

    11-08-2006, 5:00 AM
    • Loading...
    • bennedik
    • Joined on 04-22-2003, 3:59 PM
    • Posts 5

    I have the same problem on one of my pages. I am using Beta 1. I am working around this by setting one of the UpdatePanel's UpdateMode to "Always". I am not sure if this would help on your page. Does anybody know how to correctly reference a control in a different content area, or if this is a limitation for UpdatePanels?

    Martin Bennedik
  • Re: Can an Update Panel trigger on a control in a different Content area?

    11-27-2006, 7:48 PM
    • Loading...
    • JDG1
    • Joined on 04-18-2006, 2:53 PM
    • Posts 7

    I think I have found a solution:

    1.    Put your ScriptManager Control on your master page.

    2.    Do not register your triggers in the <Triggers> section of your update panel, but instead add the following code to your Page.Init event:

            If Not Page.IsPostBack Then
                Dim trigger As New Microsoft.Web.UI.AsyncPostBackTrigger
                trigger.EventName = "Click"
                trigger.ControlID = btnSubmit.ClientID.ToString
                up1.Triggers.Add(trigger)
            End If

    btnSubmit is my trigger, but you can substitute whatever trigger you have on your page for this.  Also, if you need to add more than one trigger, simply repeat the process in the Page.Init Event.

    Please let me know if this works for you.  So far, it appears to be working for me...

    JDG.
     

  • Re: Can an Update Panel trigger on a control in a different Content area?

    11-27-2006, 7:51 PM
    • Loading...
    • JDG1
    • Joined on 04-18-2006, 2:53 PM
    • Posts 7

    One more thing.  I think it is clear from the above example, but "up1" is my UpdatePanel.

    JDG.
     

  • Re: Can an Update Panel trigger on a control in a different Content area?

    11-28-2006, 10:57 AM
    • Loading...
    • JDG1
    • Joined on 04-18-2006, 2:53 PM
    • Posts 7

    After some more testing, btnSubmit.UniqueID.ToString appears to work more consistently.

    JDG.

     

  • Re: Can an Update Panel trigger on a control in a different Content area?

    01-09-2007, 8:37 AM
    • Loading...
    • marathi
    • Joined on 02-09-2005, 2:08 PM
    • Posts 34

    I tried this, but it does not work. I have a content area with three buttons and another content area with a multiview. Based on the button clicks, I want to show a specific view pane of the multiview. So the code behind each button is just - multiview.setactiveview - 0 or 1 or 2...

     The three buttons are not in update panel, but the multiview is. When I click on the buttons, the page refreshes. Using your method, I don't get the error anymore about "could not be found for the trigger in UpdatePanel", but the page refreshes on every click. However, if I move the buttons to the multiview content area, then the page does not refresh. I

     I would appreciate any help at all.

    Thanks
     

  • Re: Can an Update Panel trigger on a control in a different Content area?

    01-10-2007, 3:36 PM
    • Loading...
    • Pluginbaby
    • Joined on 11-20-2005, 8:07 PM
    • Canada
    • Posts 480
    • TrustedFriends-MVPs

    Hi,

    I think we can no more registering triggers like this in RC :

            If Not Page.IsPostBack Then
                Dim trigger As New Microsoft.Web.UI.AsyncPostBackTrigger
                trigger.EventName = "Click"
                trigger.ControlID = btnSubmit.ClientID.ToString
                up1.Triggers.Add(trigger)
            End If

    Can anyone confirm ?

    Try this one instead :

    ScriptManager1.RegisterAsyncPostBackControl(yourControl);

     

    ---
    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    ASP.NET MVP
    http://weblogs.asp.net/lduveau/
  • Re: Can an Update Panel trigger on a control in a different Content area?

    01-12-2007, 1:32 PM
    • Loading...
    • marathi
    • Joined on 02-09-2005, 2:08 PM
    • Posts 34

    How do you do that if the scrip manager is on the master page and the controls are in a content in a page that comes from master page?

    Thanks 

  • Re: Can an Update Panel trigger on a control in a different Content area?

    01-12-2007, 3:23 PM
    • Loading...
    • Pluginbaby
    • Joined on 11-20-2005, 8:07 PM
    • Canada
    • Posts 480
    • TrustedFriends-MVPs

    Hi,

    You have to expose your ScriptManager in a public property into your MasterPage codebehind.

    Then you can do :

    (MainMasterPage)Page.Master).YourProperty.... in your content page.

    [But it's better if you have a Base Page as you do not have to cast]

    ---
    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    ASP.NET MVP
    http://weblogs.asp.net/lduveau/
  • Re: Can an Update Panel trigger on a control in a different Content area?

    01-12-2007, 8:05 PM
    • Loading...
    • marathi
    • Joined on 02-09-2005, 2:08 PM
    • Posts 34

    Thanks,

    I have solved my problem by doing the following..Please let me know if there are any negative issues with doing this.

    I wrapped my 2 content areas in the master page in a update panel. Basicalle I put the content panes inside an update panel in the master page. Now on my other page, if I click on a button in one content area, both the contents get updated without the page being refreshed.

    Thanks again. 

  • Re: Can an Update Panel trigger on a control in a different Content area?

    01-13-2007, 10:20 AM
    • Loading...
    • Pluginbaby
    • Joined on 11-20-2005, 8:07 PM
    • Canada
    • Posts 480
    • TrustedFriends-MVPs

    Hi,

    I think it's ok for MultiView, anyway if you put the ContentTemplate inside an UP in MasterPage, you should read this :

    http://odetocode.com/Blogs/scott/archive/2007/01/03/9682.aspx

    ---
    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    ASP.NET MVP
    http://weblogs.asp.net/lduveau/
  • Re: Can an Update Panel trigger on a control in a different Content area?

    10-13-2008, 4:06 PM
    • Loading...
    • evaleah
    • Joined on 06-19-2006, 7:36 PM
    • Posts 33

    THANK YOU!!!!!

  • Re: Can an Update Panel trigger on a control in a different Content area?

    10-14-2008, 3:55 AM

    hi

    you can give the id from the viewsource <input name="ClinetSideControlName"  whatever the controlid rendered in viewsource give it in the

    apt.ControlId = "ClinetSideControlName";

     

    Please Mark as Answer if it helps you
Page 1 of 1 (13 items)
Microsoft Communities