in Education by
I've been struggling with some issues relating to referencing child controls within a FormView. Another developer wrote an ASPX page that is compiling and working and in that code, he references child controls within a FormView directly as properties of the page object. The page is part of an ASP.NET Web SITE Project (as opposed to a Web Application Project). We decided to convert the project to the Web Application Project model and noticed that these property references now don't compile. The code behind file does not generate the controls within the form view. While researching that issue (I had a separate post here regarding those problems), I came across something baffling. From all the posts I've read, you should always need to reference child controls within a FormView's template using FindControl -- i.e. it is supposedly not possible to do through a simple generated property regardless of whether you're in the Web Site Project model or the Web Application Project model. I was puzzled as to how my colleague's code compiled and ran. As I indicated, he is referencing the FormView's contained child controls through simple properties in the page and did not have to resort to FindControl calls. So to get to the bottom of this mystery, I cooked up the shortest example that demonstrates this phenomenon. What I found was very strange. The code I have here has a ASP:FormView with a few label controls within it's ItemTemplate. One of those labels has the ID MyComment. When the FormView databinds (to the Northwind's Products table), I simply set some text. using System; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.FormView1.ChangeMode(FormViewMode.ReadOnly); } protected void FormView1_DataBound(object sender, EventArgs e) { MyComment.Text = "Data bound at " + DateTime.Now.ToString(); } } This code will not compile because MyComment is not a valid property. Here comes the strange part. If I embed within the FormView's ItemTemplate a TabContainer control from the Ajax Control Toolkit library, the code above does compile and runs correctly. So the reason my colleague's code is compiling is because of the embedded TabContainer control within the FormView?? Why this should change the behavior of the compiler and the mechanisms by which you can get access to the FormView's child controls is a mystery to me. Incidentally, despite the fact that it compiles cleanly and runs correctly, Intellisense does not see these properties and ReSharper reports them as compile errors (by the red light in the indicator bar). Here is the markup for the page. Can anyone shed some light on this behavior? Incidentally, I'm not complaining about the fact that ASP.NET creates these properties in this circumstance. (Unfortunately, this happy, but strange, behavior, only seems to apply if the project is a Web Site Project; as a Web Application Project, property accessors don't work within the FormView even with the embedded TabControl). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
ProductID: ' />
ProductName: ' />
My Comment:
" SelectCommand="SELECT [ProductID], [ProductName] FROM [Alphabetical list of products]">
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
When you converted the Web site to a web application, did you check that the partial classes were correctly generated for your aspx files (e.g. there should be a file called "Default.aspx.cs.designer" in your web application, under the Default.aspx and Default.aspx.cs files). In a web site, these are generated on the fly by the server as your site runs and is compiled (and so don't exist in your project), while in a web application they are created and managed by Visual Studio - if they don't exist, then the code will potentially fail to compile because the objects haven't been instatiated - what is the actual compiler error are you seeing? By adding a new control to the page after you've converted the project to a web application, you are forcing VS to create the partial class that was missing.

Related questions

0 votes
    I'm building an app using Visual Studio 2010. I can run my asp.net website from my computer (by ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I am refactoring some CSS on a website. I have been working on, and noticed the absence of traditional ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Does Server Core 2008 support asp.net? I see references online saying that it isn't supported, but they ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    Does Server Core 2008 support asp.net? I see references online saying that it isn't supported, but they ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I am refactoring some CSS on a website. I have been working on, and noticed the absence of traditional ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Does Server Core 2008 support asp.net? I see references online saying that it isn't supported, but they ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I know how to use the checkboxlist in ASP.NET to display options retrieved from a database. What I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 7, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 7, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 6, 2022 in Education by JackTerrance
0 votes
    Is having to recycle an App-Pool in ASP.NET indicative of a larger problem in the Web-App? Or is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 5, 2022 in Education by JackTerrance
0 votes
    In trying to make my ASP.Net 4.0 site validate to HTML5 the best I can with the current ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    If you want to build enterprise ASP.NET MVC applications that use MSSQL databases is it better to use Windows ... integration, etc)? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I have a grid it has to display some 100 rows from a table. I do not want to set any paging ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
...