Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Controls Unseen by codebehind

Status
Not open for further replies.
Jan 9, 2003
147
US
Sorry for the Subject, I couldn't think of a good way to describe this problem. The long description is:

I just Find-and-Replaced a bunch of server control from a textbox to a label. However, the in .vb code behinds Visual Studio thinks the controls are undeclared (little blue line under lblName.Text).

The only way to get it to see the new controls seems to be to switch to HTML view in designer and make some drastic change to the HTML, which makes the IDE "see" the new control apparently.

I've even closed the project and re-opened it to no avail. There must be a way to get VS.NET to "re-read" all the controls in the .aspx files? ...I hope so anyway, I don't want to have to manually edit all these files, that's why I used find and replace!! [nosmiley]

-FD
 
You type :
<asp:textbox id="TextBox1" runat="server"></asp:textbox >
in HTML view. Switch to Design View and it is installed in the code behind.

Go back to HTML View and change it to
<asp:label id="TextBox1" runat="server"></asp:label >
Switch to Design View temporarily, and then the code behind changes the textboxes to labels.

It is the only reason I use design view.

Keeping it Simple
 
Also, make sure you close the tab for the code-behind file. If it is still open it sometimes doesn't update (The joys of VS2003!).

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Yeah, manually typing them in seems to work just fine. But what I did was something like:

Code:
Find in .aspx files: "<asp:textbox id="TextBox1" runat="server"></asp:textbox>
"
Replace with: "<asp:label id="Label1" runat="server"></asp:label>"
Found 85 matches.



Find in .aspx.vb files: "TextBox1.Text="
Replace With: "Label1.Text="
Found 85 matches.

The result should have been fine...but it wasn't.

No matter what I did (even closing VS and reopening it) would make VS see the relationship between the code I changed in the .vb file with the HTML I changed in the .aspx file.

The fastest way I found to get it to work was to double-click the build error in the task list (which would open the code-behind), switch to design view (which would open the .aspx file), then double click the new label (sending me back to the code behind). This would make the build error dissappear.

What I was looking for was a way to tell VS "You might want to double check that build error because you're wrong.
 
If you have 85 controls then it could take up to 30 seconds to change your code behind on large pages. It is not instant and there is not hour glass or progress bar. The change in code behind happens when you are in HTML view and switch to Design view. When you do this on a large page then just wait a minute. If you have some error in your ASPX script then this will not happen. You will receive a message. The most common error in ASPX script is using double quotes like
<asp:label text="<%=session("myvar")%>" runat=server />
instead of this
<asp:label text='<%=session("myvar")%>' runat=server />
with single quotes.

Keeping it Simple
 
Hi RTomes,

Thanks for the reply. Yeah, I've seen that happen too when I'm just working on a single page. And the number of controls on the page definitely has an effect on the time it takes to refresh.

This was a different case though, a project-wide search and replace. The individual pages were normal sized, not too crowded with controls. It didn't matter how many times I switched from HTML to design view, VS was definitely not going to see it on it's own no matter how long I waited. Like I mentioned before, even closing VS and reopening the project wouldn't fix it.

I finally found a fairly quick way to fix the individual pages (see post above), but it took to long for my taste (which is why I used search and replace in the first place, lol).

Maybe this is just a minor bug in VS2003 and something that will work better in VS2005.

Thanks,
-FD
 
All you have to do is switch from HTML view to Design View and back again, then save your codebehind file.

Problem solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top