Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Can not FindControl("ControlID") when the control is int contentPage

Back to Forum: Tech Off
  • User profile image
    kalchev

    Hello, I recieved strange problem and everything Ive tried to solve it - failed so hope sombody can give me a hand. The problem is that I Can not FindControl("ControlID") when the control is int contentPage. The Code is really simple:

    <%@ Page Language="VB" MasterPageFile="~/Main.master" Title="Untitled Page" %>

    <script runat="server">

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim myControl1 As Control = me.Page.FindControl("TextBox1")
            If (Not myControl1 Is Nothing) Then
                ' Get control's parent.
                Dim myControl2 As Control = myControl1.Parent
                TextBox1.Text = "Parent of the text box is : " & myControl2.ID
            Else
                TextBox1.Text = "Control not found....."
            End If
        End Sub
    </script>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:TextBox ID="TextBox1" runat="server" Width="579px"></asp:TextBox>


    </asp:Content>

    Any Idea is welcome
    Thank YOU

  • User profile image
    kalchev

    I've soleved it but when it is with textbox
    it works when  is like:
    Master.Findecontrol.....

    But when it is imageButton it doesn't
    Any Idea:)

  • User profile image
    codeyoda

    I had the same problem.  The syntax I used was similar to your solution:

    Page.Controls(0).FindControl("ContentPlaceHolder1").FindControl("ControlID")   

    I haven't tried the image button yet, but I'll see if I can offer any help with that.

  • User profile image
    kalchev

    Thank You CodeYoda id works great:)

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.