473,747 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PlaceHolder misbehavior under GridView?


The funniest part of the problem described here is that I am not new to
ASP.NET, but honestly here I have no idea about what's going on.

I have a GridView with a data source that just returns 1 row of only 1
The GridView has only one field, a TemplateField.

In GridView.RowCre ated, I create a TextBox under a PlaceHolder statically
declared in the ItemTemplate.

In GridView.RowDat aBound, I assign a Text value to this TextBox.
I've added a Button to my page to be able to initiate a simple postback.
The idea is to make sure the text value of the TextBox is properly restored
upon postback.

As simple as it might seem, it just doesn't work.

If I add the TextBox *to the Cell* where the PlaceHolder is declared,
everything works as expected

Now if I do want to create this TextBox under the PlaceHolder, FindControl
doesn't work in RowDataBound upon postback (returns null).
Even if I don't use FindControl and manually add then retrieve the TextBox
through phData.Controls[0], the ViewState is not applied upon postback.
This looks like a problem with the PlaceHolder to me.

Can somebody explain me why I get this behavior?


Here is the markup:

<asp:GridView ID="gv1" runat="server" DataSourceID="d s1"
AutoGenerateCol umns="False" DataKeyNames="N ame"
OnRowDataBound= "gv1_RowDataBou nd"
OnRowCreated="g v1_RowCreated">
<asp:TemplateFi eld HeaderText="Col umn1">
<ItemTemplate >
<asp:PlaceHolde r ID="phData" runat="server" />
</asp:TemplateFie ld>

And here is the code:

protected void gv1_RowCreated( object sender, GridViewRowEven tArgs e)
if (e.Row.RowType == DataControlRowT ype.DataRow)
// This works
// Control whereToAdd = e.Row.Cells[0];

Control whereToAdd = (PlaceHolder)e. Row.FindControl ("phData");

TextBox tb = new TextBox();
tb.ID = "heho";
whereToAdd.Cont rols.Add(tb);

protected void gv1_RowDataBoun d(object sender, GridViewRowEven tArgs e)
if (e.Row.RowType == DataControlRowT ype.DataRow)
// This works
// Control whereToAdd = e.Row.Cells[0];

// FindControl returns NULL here. Why?
Control whereToAdd = (PlaceHolder)e. Row.FindControl ("phData");

TextBox tb = (TextBox)whereT oAdd.FindContro l("heho");
if (tb == null)
tb = new TextBox();
tb.ID = "heho";
whereToAdd.Cont rols.Add(tb);
tb.Text = "OKAY";

Sep 22 '07 #1
0 1979

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't know exactly where the table will be located on the page until runtime. Before the form control table is added to the Placeholder, I'm adding a whole bunch of tables to the Placeholder. This is a flowchart program and I have multiple action boxes...
by: Mike Speak | last post by:
I have a user control that I want to use to render 4 menu items (retrieved from db) on the top of each of my asp.net pages. The user control defines a table, with one TR and one TD. Within the TD I have a placeholder defined: <asp:PlaceHolder ID="categoriesPlaceHolder" Runat="server" /> In the code behind of the user control, on the Page_Load event I am retrieving data from db and adding controls to the placeholder as
by: Dan | last post by:
I have an asp.net page default.aspx with a user control and a placeholder control. <html> <body> <form id="myform" method="post" runat="server" /> <PageHeader:Header id="header1" runat="server" /> <asp:PlaceHolder ID="content" runat="server" /> </form> </body>
by: Chad Crowder | last post by:
Is it possible to create a placeholder inside a template column of a datagrid? My goal is to use a placeholder, and during runtime add user controls to the placeholder as the items in the datagrid are being built. I've tried doing this with a simple link button, but I get the "Object Reference not set to an instance of an object" whenever I try to view the page. Here's the html code for the placeholder in my datagrid: <ItemTemplate>
by: shark | last post by:
I have a placeholder in a control that is in turn, used as a control in a placeholder in a form. I am getting a viewstate error so I believe I have to clear my placeholder before I load the control within the control. How to I address this placeholder to clear it? The following gives me a null object error: PlaceHolder myPlaceHolder =
by: Angel | last post by:
I have added controls to the placeholder control. All the controls that were added have EnableViewState = true including the placeholder. One of the controls has a button that performs a postback. My question is when the button is clicked and a postback is performed, the controls that were in the placeholder no longer appears on the screen! Am I doing something wrong here? Why are the controls back on the screen eventhough they have enable view...
by: Dica | last post by:
i need to dynamically add a web control to a page without using placeHolder. i'm looping through all the files in a folder and creating a table row as string for each file. the contol is to be nested in that row as follows: sTblRow = "<tr><td>" + sFrom + "</td><td><asp:DropDownList id=\"lstAction_" + filename + "\" runat=\"server\<asp:ListItem Value=\"deliver\">Deliver</asp:ListItem><asp:ListItem...
by: David Colliver | last post by:
Hi, using vb.net 1.1 I am trying to add a control to a placeholder but am having problems with it. I do it practically the same way as i do in C# (I have more C# skill than VB.NET)and I have asked someone with more VB experience to look at it and they can't see why it fails.
by: Brad Baker | last post by:
I am trying to programmatically set a placeholder control in csharp which is nested inside a repeater control between <ItemTemplateand </ItemTemplate> tags, however I am running into problems. I've tried several different approaches for finding the placeholder: This: MyControl = this.FindControl("$form$tabs_repeater$PlaceHolder1"); Produces this error: Object reference not set to an instance of an object.
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.