Finding Value of Dynamic Control in MasterPage/ContentPage System

Discussion in 'ASP .Net' started by dawg1998, Mar 15, 2006.

  1. dawg1998

    dawg1998 Guest

    I have a page that creates dynamic textboxes based on the number of
    fields a user chooses to fill out.

    This process worked great when the page was standalone. However, when I
    move to a Content/MasterPage setup, the MasterPage Form seems to be
    interfering with the ability of my code to retrieve the value in the
    dynamic control.

    Are there any ideas on why this is happening or how to work-around the
    problem? What is the syntax to find a dynamic control within a form
    established on a Master Page? The two methods I have tried so far
    always gets me the "Object reference not set to an instance of an
    object" error.

    A quick example is below. The name of the form established in the
    MasterPage is "frmForm". I must place the form tags within the
    MasterPage because of the presence of a SiteMap menu control that
    resides in the MasterPage.

    <%@ Page Language="VB" MasterPageFile="~/Sys_Masters/MasterPage.master"
    title="Dynamic Control in Master Page" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="cphContent"
    Runat="Server">

    <script runat="server">

    Sub Page_Load()

    Dim txtbxTextBox As New TextBox()
    txtbxTextBox.ID = "txtbxTextBox"
    phPlaceHolder.Controls.Add(txtbxTextBox)

    End Sub

    Sub btnSubmit_OnClick(ByVal sender As Object, ByVal e As
    System.EventArgs)

    Dim txtbxTextBox As New TextBox()

    '// Neither of the two methods below finds the control
    'txtbxTextBox =
    Master.FindControl("frmForm").FindControl("phPlaceHolder").FindControl("txtbxTextBox")
    'txtbxTextBox = CType(Master.FindControl("frmForm").FindControl
    "phPlaceHolder").FindControl("txtbxExample"), TextBox)

    lblValue.Text = txtbxTextBox.Text


    End Sub


    </script>

    <asp:Label ID="lblTitle" runat="server" Text="Dynamic Control in Master
    Page Test: "/>
    <p />
    <asp:placeHolder ID="phPlaceHolder" runat="server"/>
    <p />
    <asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_OnClick"
    Text="Submit" />
    <p />
    <asp:Label ID="lblValue" runat="server" />

    </asp:Content>
     
    dawg1998, Mar 15, 2006
    #1
    1. Advertising

  2. dawg1998

    Simon Guest

    Oops, I realized this morning that the page I was having that problem
    in had never been run so I didn't realize that i was talking out of my
    ass since that solution doesn't work.
    What ended up working was first getting the ContentPlaceHolder control
    and then using findcontrol from there:
    ContentPlaceHolder mainContent;
    mainContent = (ContentPlaceHolder)Master.FindControl("MainFormHolder");

    DropDownList ddl =
    (DropDownList)mainContent.FindControl("controlname");

    That one ought to work for you, sorry about the idiocy :)
    Simon
     
    Simon, Mar 16, 2006
    #2
    1. Advertising

  3. dawg1998

    zehramb

    Joined:
    May 31, 2010
    Messages:
    1
    Dynamic Fields with Master page

    Hi....

    I am also finding the same problem.but unfortunately this solution doesn't work for me.
    Please anybody tell me how to solve this.
    I have same Dynamic fields created with web content form.But i am not able to find the dynamically created control.
    I have used two methods but both failed..
    I have taken one placeholder which is having id "PlaceHolder2"
    This is the code what i have tried.

    First Method:
    Dim mainContent As ContentPlaceHolder
    mainContent = Master.FindControl("PlaceHolder2") // i am not able to find this placeholder.mainContent is "Nothing"
    Dim tbtemp As TextBox
    tbtemp = mainContent.FindControl(strControlName)



    Second Method:
    Dim tbtemp As TextBox
    tbtemp = Page.FindControl(strControlName)
    strValue. = Request.Form(strControlName)

    Please help me...what i am missing here????
    Also note that this methods work with web form without master page.....
     
    zehramb, May 31, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    501
    Scott Allen
    Nov 22, 2005
  2. User
    Replies:
    9
    Views:
    10,437
  3. =?Utf-8?B?ZGF3ZzE5OTg=?=
    Replies:
    0
    Views:
    485
    =?Utf-8?B?ZGF3ZzE5OTg=?=
    Mar 15, 2006
  4. Replies:
    7
    Views:
    13,150
    TuckWong
    Jan 11, 2013
  5. Elmo Watson
    Replies:
    1
    Views:
    603
    Eliyahu Goldin
    May 8, 2007
Loading...

Share This Page