Page/Controls Inheritance in ASP.NET 2.0

N

netasp

hi guys,

I am having the following problem:
I am trying to access some textbox & dropdown controls from my function
located in the app_code folder but I can't see them, it complains about not
being declared! or not found.

it was working in VS 2003 before the migration; since there is no App_Code
but now since I moved it, I can't seem to figure out how to make it see the
controls sitting on the aspx form from a shared class sitting in the
app_code folder?

for example lets say the function is:

public shared MarkScheduleLength()

dim i as integer
dim s as string

i = ctype(txtLength.Text,integer) 'it complains about txtLength.Text
is not declared
s = cmbName.SelectedValue 'it complains about cmbName is not
declared

........

I don't want to create an instance of the form because I am trying to
capture the exact value of that control at that time(as it changes) and not
creating a new instance of it with a new value, I am trying to capture
cmbName_SelectedIndexChanges(....) everytime the user changes the drop down
menu selection

how can I work around this?. I have a lot of functions and methods that
access textboxes, dropdown menus, labels, ...etc as their value changes at
runtime and now I am stuck, it can not see any of them.

did Microsoft disable controls access because of this move to App_Code
folder? they didn't think of that?

Please let me know
thanks
 
B

bruce barker

you pages shoudl implement an interface, then the appcode can cast the
current page to the interface and access the form fields. or simular to
version one the appcode is a base page (which defines the fields) and
your pages inherit from it

-- bruce (sqlwork.com)
 
W

Walter Wang [MSFT]

Hi netasp,

Would you please tell me more about how the code is written in ASP.NET 1.1?
This way I could give more detailed suggestion on how to migrate them to
ASP.NET 2.0 successfully. Thanks.


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

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

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

netasp

thanks Walter for your reply,

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 simple way because the class for
that form is placed in an 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.
 
N

netasp

thanks Bruce for your reply,

thats a complete re-write, specially if you have more than 100
methods/functions then it would be cleaner to re-write the application then
migration, i don't think Microsoft would make us make something stupid like
that. there must something easier then writing interface or creating an
instance of the class everytime you are trying to get a value from a textbox
or dropdown menu which should be no-brainer!

i don't know why Microsoft would do something like that!

i might be wrong, i don't know...

thanks
 
W

Walter Wang [MSFT]

Hi netasp,

Do you mean that code files such as Default.aspx.cs are moved to App_Code
directory too? The App_Code should be used only to place other classes
(i.e. not the code behind file of web form). The code behind files such as
Default.aspx.cs should stay in the same directory with its web form file
(*.aspx or *.ascx).

Would you please tell me some detailed steps how you migrated the 1.1
projects? Based on my understanding, the migration wizard will NOT create
the App_code folder and put all the source files there for you.

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.
 
W

Walter Wang [MSFT]

Also, as other community members suggested, the Web Application Project
add-on for VS2005 (included in SP1 or as standalone installation) will
maintain the same web project model as in VS2003. Therefore you will be
still be able to use familiar project model with new features introduced in
ASP.NET 2.0.


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.
 
G

Guest

hello Walter,

the migration does not move everything to the App_Code folder, only the
classes (.vb)
so whatever methods and functions i used to have behinde any aspx form,
after migration that class ONLY will move into the App_Code folder and .aspx
form will stay in its place. so for example:
Default.aspx would stay in its place and Default.aspx.vb would move into the
App_Code folder and that what is causing the problem.

Now, what marss has suggested is every interesting and i am going to check
it out, I didn't know about Website vs Web Application and I usually create
New WebSite !! because its the obvious thing to any user.

sorry about the late reply since all of these posts are not showing in my
outlook express for some reason
 
W

Walter Wang [MSFT]

Hi netasp,

Thank you for update.

I'm still not able to reproduce the issue from VS2003 to VS2005 (sp1 or no
sp1). Anyway, the Web Application Project add-on should maintain the
similar web project model from VS2003, therefore I believe this should not
have this issue on your side. Please let me know the result. 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.
 
G

Guest

hi Walter,

yeah, the SP1 fixed this problem by bringing back the web application project.

thank you very much for your support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top