ASP.Net 2.0 - App_Code Folder

  • Thread starter Thread starter netasp
  • Start date Start date
N

netasp

hi all,

when adding a new web form in VS 2003, usually viewing the code behind for
that form will let you write any method or function and referencing any web
control placed on the form without any problems, for example writing a
function that grabs a string value from a textbox is as easy as saying:
dim str as string = me.TextBox1.Text

but with visual studio 2005 I can't do this in the simple way because the
class for
that form is placed in the app_code folder and it will not see non of the
controls on the web form, so saying:
dim str as string = me.TextBox1.Text will not work and it complains about
the TextBox1 is not defined. in more details, I have a function was working
in visual studio 2003 that calls a stored procedure in sql server 2005, this
function passes a variables (3 variables) from a 3 textboxes on the form.
And I am calling this function everytime the user changes the value of one
of these textboxes.

now since the migration, visual studio 2005 puts all classes under Ap_Code
folder (as one of their new features!!) moving my function under the
App_Code folder prevents me from calling/Getting the values of those
textboxes as they change why? because the class can't see those controls
sitting on the form!

thanks for your help.
 
Hi netasp,

You can find more information about common ASP.NET 2.0 conversion issues
and solutions here:

#Common ASP.NET 2.0 Conversion Issues and Solutions
http://msdn2.microsoft.com/en-us/library/ms972973.aspx


From the document, you will see following changes are related to your issue:

--------------------
In ASP.NET 1.x, the graphical components were typically separated from the
coding components using an .aspx page and a code-behind file. The .aspx
page is derived from the code-behind file. This means that you have to
declare all your controls in both classes in order to properly wire up the
callback events. The inheritance relationship also caused some problems
with synchronizing the classes, especially when a developer made a change
to the .aspx (such as adding a control), without making the necessary
changes to the code-behind or recompiling the application.

In ASP.NET 2.0, the code separation model has changed, thanks to the advent
of a concept known as the partial class. The partial keyword lets you split
the code for a single class into two separate files. The code-behind file
defines a partial class that contains user code. The designer will also
generate a stub file containing a partial class that defines the field
declarations for the controls used in the aspx page. When compiled, the
.aspx page will derive from the combined partial classes, and be compiled
into its own page assembly. This design reduces the risk of inadvertently
breaking the page by editing designer-generated code.

The conversion wizard updates your application by moving all standalone
code to the App_Code directory.
--------------------


I think maybe some of your code are standalone and therefore they're
migrated to App_Code. However, based on my test, if the code file is a
CodeBehind class for a WebForm, it will not be migrated to App_Code.

Would you please create a simpler reproducible VS2003 web project and send
it to me? I can verify the migration behavior on my side. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top