Is the control that you're looking for on the same level as that of the control that you're searching from from the findcontrol method. The findcontrol method does not dig into child controls. This could possibly be your issue. If so you may want to write
a loop/recursive function to dig down into the child controls until you find it.
dangerouscho...
Participant
1021 Points
407 Posts
VB.NET - Unable to fine control inside usercontol and master page
Mar 29, 2010 08:48 AM|LINK
Unable to find control inside the usercontrol in vb.net
code of master page
<head runat="server"> <title></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> </head> <body> <form id="form1" runat="server"> <div> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> <div> <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"> </asp:ContentPlaceHolder> </div> <div> <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server"> </asp:ContentPlaceHolder> </div> </form> </body>code of master page 2
<%@ Master Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="MasterPage2.master.vb" Inherits="MasterPage2" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> put a web user control for the navigation </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server"> advertise </asp:Content> <asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" runat="Server"> <table> <tr> <td> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </td> <td> <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"> </asp:ContentPlaceHolder> </td> </tr> </table> </asp:Content>In the web user control i have insert some link buttons like home, contact etc...
in the default page i want to change the linkbutton css class inside the user control....
i am always get nothing value.......
can anyone solve this issue in vb.net
Please 'mark as answer' my post if they are helpful.
fashfaq
Participant
1175 Points
294 Posts
Re: VB.NET - Unable to fine control inside usercontol and master page
Mar 29, 2010 10:48 AM|LINK
please use this code
Ctype(Master .FindControl("textbox1"),TextBox) ' For Master Page
Ctype(Master .FindControl("UserControl").FindControl("TextBox"),TextBox) ' For Master Page user control
Fawad Ashfaq
Software Engineer
please Mark Answer if helpful
dangerouscho...
Participant
1021 Points
407 Posts
Re: VB.NET - Unable to fine control inside usercontol and master page
Mar 29, 2010 11:19 AM|LINK
this doesn't work
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">Dim link As LinkButton</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> link = CType(Me.Master.FindControl("LinkButton1"), LinkButton)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> link.Text = ""</div>Dim link As LinkButton
link = CType(Me.Master.FindControl("LinkButton1"), LinkButton)
link.Text = ""
why?
and tell me the packages import in the master page and default page
Please 'mark as answer' my post if they are helpful.
anhphan
Participant
863 Points
190 Posts
Microsoft
Re: VB.NET - Unable to fine control inside usercontol and master page
Mar 29, 2010 09:10 PM|LINK
This article is helpful http://aspalliance.com/1737_CodeSnip_Find_Control_in_Nested_Master_Pages.all
For your project, I assume that you have a user control inside "Content2" of the nested master page. Then you can do something like
ContentPlaceHolder outerCP = (ContentPlaceHolder)Page.Master.Master.FindControl("ContentPlaceHolder1"); WebUserControl uc = (WebUserControl)outerCP.FindControl("WebUserControl1"); LinkButton lnk = (LinkButton)uc.FindControl("LinkButton1"); lnk.Text = "Text was changed";It's in C#. You can do similar thing in VB. Hope it works for you.
davleus2
Member
78 Points
26 Posts
Re: VB.NET - Unable to fine control inside usercontol and master page
Mar 29, 2010 10:20 PM|LINK
Is the control that you're looking for on the same level as that of the control that you're searching from from the findcontrol method. The findcontrol method does not dig into child controls. This could possibly be your issue. If so you may want to write a loop/recursive function to dig down into the child controls until you find it.
Hong-Gang Ch...
All-Star
74696 Points
6768 Posts
Re: VB.NET - Unable to fine control inside usercontol and master page
Apr 01, 2010 05:31 AM|LINK
Additionally,
Convert C# to VB.
If you have any feedback about my replies,please contactmsdnmg@microsoft.com.
Microsoft One Code Framework