December 7th, 2011, 09:19 AM
UserControl & MasterPage Ajax control references in code behind
I'm having two issues - both relating to referencing controls from the child page's code behind.
The first involves referencing a panel control on a user page to change the color at the click of a button on the child page holding a master page. I've done this successfully without a master, but can't seem to get it right with the master. First and second tries listed:
<%@ Register Src="~/inc/ceSteps.ascx" TagName="ceSteps" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<uc1:ceSteps ID="ceSteps" runat="server" />
Then on the code behind for my page:
Dim myCtrl As UserControl = CType(FindControl("ceSteps"), UserControl)
myCtrl.pnlStage1.BackColor = System.Drawing.ColorTranslator.FromHtml("#dfdfdf")
yahda, yahda, yahda....
Protected MyCtl As Panel
Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init
MyCtl = DirectCast(FindControl("pnlStage1"), Panel)
Protected Sub btnStep2b_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStep2b.Click
MyCtl.BackColor = Drawing.Color.Azure
The second failure to reference correctly is with a reference from the code behind on a child page at a button click to a placeholder on the master page within an ajax expanding menu. I get object reference errors. The placeholder outside of the accordion produces no errors. Here's my first two tries:
CType(Page.FindControl("$Accordion1$accPane1$phProfile"), PlaceHolder).Visible = True
Dim myAcc As Accordion = TryCast(Master.FindControl("Accordion1"), Accordion)
Dim myAP As AjaxControlToolkit.AccordionPane = CType(myAcc.FindControl("accPane1"), AjaxControlToolkit.AccordionPane)
CType(myAP.FindControl("phProfile"), PlaceHolder).Visible = True
CType(Master.FindControl("phProfile"), PlaceHolder).Visible = True
And, the master page doesn't reflect the change on the correctely referenced control with a click of a button on the child page until another page with the same master is loaded. Any way to reference it on the original child page and the force the master to refresh or something?
I know this is more than one question, but the referencing issues seems to be related to me. Thanks for any help.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.