Finding a controls inside a FormView which is inside a MasterPage


I have few controls (textboxes) inside a FormView that is inside a MasterPage. The findcontrol doesn't work for me or I'm not doing it right. If I JUST use the FormView or JUST the MasterPage then the findcontrol works. For example TextBox idTextBox = (TextBox)FormView1.FindControl("TextBox1"); works if I don't use the MasterPage.

Can someone please help? How do you find a control inside the FormView1 that is inside the MasterPage?

Any help would be appreciated.

3/29/2007 7:48:28 PM 13714 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 30
Get it on Google Play
Get it on Apple App Store

Hi, friend:

  Try this:

        FormViewRow fr = ((FormView)Master.FindControl("FormView1")).Row;
            if (fr.FindControl("TextBox1") != null) Response.Write(((TextBox)fr.FindControl("TextBox1")).Text);


Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
3/30/2007 7:22:37 AM

Thank you Allen.

I tried using your method but for some reason it kept throwing the NullException. Your answer lead me to find the solution a bit it is if anyone else has the same problem:

Simply use the PreRender method and check which mode you are my case I want to find the control in the Insert mode.

if (FormView1.CurrentMode == FormViewMode.Insert) {

   TextBox test2 = (TextBox)FormView1.FindControl("TextBox1");

   test2.Text = "I found you!";


3/30/2007 4:53:07 PM

You need to make sure that you have the tag that gets added because of your master page.


        var imageTagID = "<%= TextBox1.ClientID %>";
        imageTagID = imageTagID.replace(/TextBox1/i,"");

put that as a global then you can use the following syntax:

                var myObject = document.all ? document.all[imageTagID+"TextBox1"] : document.getElementById(imageTagID+"TextBox1");

Which will return your object.




4/2/2007 4:11:20 AM

Similar Artilces:

Controls inside formview inside formview
Hello, I'm trying to insert data into a label that is located in a formview which is located in a formview.  This is what I got so far: Private Sub Test()    Dim fvSecondView As New FormView    fvSecondView = Me.FormView1.FindControl("SecondView")    Dim lblData As New Label    lblData = fvSecondView.FindControl("DataLabel")    lblData.Text = "Some Data" End Sub Now this does work to get data out if I change the last line to: testlabel.text = lblData.Text But just can't seem to get the data to go ...

FileUpload control inside UpdatePanel inside user control inside popup
Hi,     The Asp.Net File Upload control is not working inside update panel. Acutally i have put the FileUpload control inside User Control again inside update panel. Since the update panel does async postback. The posted file is null in the server side. When i do full page level post back it works. but i have to put it inside update panel. How to do it? Becuase the FileUpload control should be in Ajax Model Popup Extender where i have to put update panel to avoid closing of popup after fullpostback. Since the ajax model popup extender is getting closed after full post b...

How do I control parameter a control that is inside a formview that has another formview in it?
I have a formview2 within another formview1 but I want to control parameter from a sqlDataSource3 outside the formview a control that is in formview2<asp:SqlDataSource ID="SqlDataSource1" SelectCommand='SELECT "USER,UID" FROM "TUSERS"'><asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">    <ItemTemplate>        <asp:Label ID="Label1" runat="server" Text='<%# Bind("USER") %>'></asp:La...

How to find the ID of a web control tht sits inside a FormView Control Template?
I need advice how to find the ID of a control inside a template. Say a DropDownList inside the Insert template of a FormView When looking at the DropDownList in the Solution Explorer its ID is f. ex. DropDownList1 When looking up to the dropdownlist of controls on the page my DropDownList is : FormView1.InsertItemTemplate.InserItemTemplate.DropDownList1 But neither of these IDs can be used to reference the control in a code behind page What to do? You can't directly access controls nested inside of another control. You have to access them programmatically. This should work you will n...

How I can accede to the controls that they find inside a formview from VB.NET
Hi again: How I can accede to the controls that they find inside a formview, to use its values, to modify or validate it, from  VB.NET. For example I have the next page Items.aspx: <table border="0" cellspacing="0" cellpadding="0">     <tr>        <td><asp:TextBox runat="server" ID="MinIDProducto" Text="" /> </td>        <td></td>     </tr>     <tr>        <td><asp:Tex...

Referencing Nested FormView Control inside the EmptyDataTemplate of a FormView Control
Hi all,I am very new to ASP.Net and have been working on a particularly frustrating problem now for days and cant seem to find an answer to it. I am building a front end to a newly created database and have set 2 session variables that I am using to set default values using the FindControl Method. this works fine until I need to set default values in a nested control. IE...I have a form view control and in that controls EmptyDataTemplate I have another form view control with about 10 fields using the same datasource as the parent form view. I need to place default values in 2 of those fields...

SqlDataSource with FormView: Referencing a control inside FormView as control parameter?
I have been looking at this website and was wondering...what if my FormView control had a textbox or label inside of it in its EditTemplate item...can I link my SqlDataSource object (which is also bound to the FormView control) to that control meaning specify control parameter as the textbox which is inside the FormView...? PS: I use vbexpress 2005 programming blog Hi:   You can try something like: <asp:ControlParameter ControlID="FromView1$DropDownList1"   But please make sure the DropDownList (or any other controls) be available all the time. In anoth...

controls not visible inside formview control
I am trying to write a query to select data from one table based on the resultof a drop down list that pulls data from another table. The query I am writing is: "SELECT church.churchName, church.churchId AS Expr1 FROM [churches]WHERE ([deanery.deaneryId] = @churches.deaneryId)"I am using a sql source controlNow I found an example from a website that pulls data from one drop down list and usesthe selected value to populate the second drop down list. But, the controls are not part of a formviewcontrol. So my question is how do I get the dropdownlist control that is located...

How to find control inside ajax controls
1)First i have Tab Panel (tbPanel) 2)have a Grid View inside the Tab panel (grdView) 3) I have a panel with the text box (txtTest)   How to find the control of the text box      Try it through finding it through the event on the control the fires it the following example is of a dropdown list that's inside a gridview (grid view has a couple of update panels in it and thats why there are more than one parent). int selectedRow = ((sender as ListBox).Parent.Parent.Parent as GridViewRow).RowIndex;  this is on the SelectedIndexChanged of that dropdown &nbs...

how to find control inside a placeholder control ?
I have a table control named PrintTable, which is dynamically generated. I place it to a placeholder control (phPrintQ) on the page, and it renders well: phPrintQ.Controls.Add(PrintTable); However, when I want to retrieve the table control from the placeholder control (phPrintQ), I could not do it : Table t = (Table)phPrintQ.FindControl("PrintTable"); foreach (TableRow tr in t.Rows) { Response.Write(tr.Cells[0].Text);} This is the error message: Object reference not set to an instance of an object  on my foreach loop (t.Rows). Please help !!.. Thanks       ...

Cascading Dropdown error in formview controls and finding all controls in formview controls
can help with the following? Instantiate Cascading Dropdowns within Formview controls (this returns the error message "databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control".) Pass values between controls within master controls such as Textboxes within formviews (example: Pass the selected value in a dropdownlist to another textbox both WITHIN a formview control) Expose the public properties of a master page Hi arraybiz, 1) I need your code. See sample:

How to find Checkbox control inside ReorderList control
I have a Checkbox control inside of the ReorderList control, <ItemTemplate> area. How would I find the control to determine if that checkbox is checked and get the datakey for it? examples would be great. thanks! This works the same as it does with other repeaters.  If you get a reference to the data item (e.g. the row), you can do a FindControl("Checkbox1") or whatever. It's hard to give an example without some more context about what you are trying to accomplish, but say you want to get all of the Checkbox values in a button click or something:   protected v...

cannot find label control inside detailsView control
hi floks, i cannot find label control inside panel control from codebehind. any ideas?Jagjot SinghMCP, CCNA Are you using Panle.FindControl("label1")Cheers,Emad Yazdanpanah From 1.  If the label  is in .....DetailsView ....ItemTemplate  <asp.label label1 ....>  find using GridViewRow.FindControl("label1") as Label  2.If the label is in normal panel should see the label control otherwise close the project and VStudio and Open again .Should work  If this solves your problem plea...

Find control inside a datapager which inside a listview
Hi there, I have a button that I have added inside a datapager which I am trying to add some code to on the ListViews ItemDataBound event. For the life of me I can't seem to find it!I can find the pager using  protected void lvReports_ItemDataBound(object sender, ListViewItemEventArgs e) { DataPager dp1 = (DataPager)lvReports.FindControl("pagerReport"); if (e.Item.ItemType == ListViewItemType.DataItem) However when I try the button using Button btn = (Button)dp1.FindControl("btnExportReport"); I can't find it and btn is been retur...

Web resources about - Finding a controls inside a FormView which is inside a MasterPage -

Chuck Norris - blksthl
... Norris doesn't set an executionpolicy for Powershell. Chuck Norris Policy is to execute everyone. Chuck Norris never uses a SharePoint Masterpage. ...

“I Saw a Nazi”
... SEE YOU IN A YEAR! 18:28 - Pictures of reconstruction groups: Kacper Gizbo ( pictures of marching of reconstruction groups: ...

Ajax and forms authentication
Forms authentication is nice way to protect your web pages from unauthorized views. The good thing is that it shields all request for ...

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Startup Pakistan
Pakistan has a whole host of problems. So does every other country in the world. The trouble is that the name Pakistan carries an increasingly ...

Keep, share, and discover the best of the Web using Delicious, the world's leading social bookmarking service.

Free Summary Report
Turn on more accessible mode Turn off more accessible mode Skip Ribbon Commands Skip to main content Turn off Animations Turn on Animations Contact ...

Brendan Enrick
Archive - Brendan Enrick

M ore d otnet .NET Interview Questions, ASP.NET, C#, VB.NET, XML, SQL Check Out √ .NET NOTES OOPS in .NET .NET ...

Using a nested Master Page with ASP.Net
The first thing I actually missed from Webforms are nested masterpages. Fortunately they’re not missing at all, they just figured out those MVC ...

Resources last updated: 12/13/2015 9:32:48 AM