View Full Version : I'm losing my textbox reference...

03-29-2007, 06:20 PM
This is seriously doing my poor head in.

I had layout troubles with most of my website, so I changed most of the tables for divs, the result is exactly what I wanted, and this is great. (Thanks to the answer I got here :D)However, I have a search interface that used to work before I changed the layout, and now just doesn't work anymore because my textbox is gone wild. Just to give you an idea of the structure of the whole thing:

Master Page
UserControl Containing the search interface

The user control contains a tabcontainer with 5 tabpanels inside a div (which was there before I changed the layout, so they're not the source of the problem), and my search interface is within one of the tabpanels, inside a panel with a default button which is the search button. There's a searchHeader div containing both the button and the textBox thats causing the problem. Here, a bit of code never hurt anyone.

<div style="text-align: left; height: 100%;">
<ajax:TabContainer ID="tabBlog" runat="server" Width="98%" CssClass="my_ajax__tab_xp">
<ajax:TabPanel ID="tabRecherche" runat="server" HeaderText="Recherche" Height="100%">
<asp:Panel DefaultButton="btnSearch" runat="server" ID="pnltest" Height="100%">
<div id="headSearch">
<asp:TextBox ID="txtSearch" runat="server" MaxLength="100" />
<asp:Button ID="btnSearch" runat="server" Text="Rechercher..." UseSubmitBehavior="true" />

<%-- rest of the search interface --%>

The problem here is that, no matter what I'll type in the textbox, the code of the page won't be able to find thetext in the textbox. It STAYS there after postback, but it shows as txtSearch.Text = "". I tried setting the text attribute directly into the textbox in the asp code. It'll show up on the first load, if I change it, it'll stay at what i set it in the text, but it'll show what I changed it to. It's as if the textbox was being detached from the rest of the page after loading, and I really don't get why. The only part of the code that affects the textbox in any way is in the Load_Search method that actually just does the search as it should.

I also tried setting the textbox text in the page_load sub (that is actually the one that calls Load_Search).

If txtSearch.text = "" then
txtSearch.text = hello
End If
Same thing, when I first load the page, the text is as what I set it to in the page_load. If I change it in the form, it doesn't change the text value at code level.

the button doesn't have an event associated with it. The only thing it does is a postback, and then the postback will reload the search form according to whats in the textbox, thus displaying the results without having to add anymore code handler. Worked fine up to yesterday when I started playing with divs, but it doesn't make sense that I can access the control from the page load, and not from another sub in the same page, same codebehindfile, and executed basically at the same time.I even tried
Dim txtSearch2 as textbox = pnlSearch.FindControl("txtSearch")

and it still returns me the content of an emtpy textbox, no matter whats written in it. Anyone has an idea?

03-29-2007, 07:48 PM
ack, after searching and testing so many many things, I finally realized that I was loading my usercontrol dynamically, and thus on the page load, the controls don't have their values set yet... -_-'

I fixed it by simply shifting my Load_Search sub call into an If Not IsPostBack block in the page_load and also calling it in the button_click event code... That was simple enuf