If I use a code behind class for an aspx page, what is the best way to get
data from the codebehind class into my aspx page?
I know about databinding, but is there a more basic way of just referencing
the variables or calling getters?
thanks in advance 12 1597
Just drop a label (or any control that support text/data representation).
For a control that displays text (like a textbox or label), just set the
text property of the control to the value from the codebehind. For
something like a checkbox or radiobutton, you'd set the checked property of
the control based on the boolean value in the codebehind.
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:ud***********************@twister.nyc.rr.com. .. If I use a code behind class for an aspx page, what is the best way to get data from the codebehind class into my aspx page?
I know about databinding, but is there a more basic way of just
referencing the variables or calling getters?
thanks in advance
OK, thats clear. But how do I reference the value of the codebehind.
lets say I have a codebehind object, that I instantiate in the aspx page
within the pageload event like
void Page_Load(Object Src, EventArgs E) {
XMLManager xman = new XMLManager();
xman.ReadXML();
}
within the XMLManager class I have a
public String testStr;
which I set....how do I retrieve that value?
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:uN**************@TK2MSFTNGP12.phx.gbl... Just drop a label (or any control that support text/data representation). For a control that displays text (like a textbox or label), just set the text property of the control to the value from the codebehind. For something like a checkbox or radiobutton, you'd set the checked property
of the control based on the boolean value in the codebehind.
Don't think of it as "pulling" the value from the codebehind to the aspx
page. Instead "push" the value from the codebehind to the aspx page.
In other words, you wouldn't need to grab the codebehind value testStr from
the aspx page. Instead, place a label (for example) on the aspx page and in
the Page_Load event of the codebehind place the string value in the label.
In the .aspx page:
<ASP:LABEL ID="lblDataHolder" RUNAT="Sever"></ASP:LABEL>
In the codebehind:
void Page_Load(Object Src, EventArgs E) {
XMLManager xman = new XMLManager();
xman.ReadXML();
//This takes the public string value in the class and places it into the
label on the web page
lblDataHolder.Text = xman.testStr;
}
-Scott
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:Ek***********************@twister.nyc.rr.com. .. OK, thats clear. But how do I reference the value of the codebehind.
lets say I have a codebehind object, that I instantiate in the aspx page within the pageload event like
void Page_Load(Object Src, EventArgs E) {
XMLManager xman = new XMLManager(); xman.ReadXML();
}
within the XMLManager class I have a
public String testStr;
which I set....how do I retrieve that value?
"Scott M." <s-***@BADSPAMsnet.net> wrote in message news:uN**************@TK2MSFTNGP12.phx.gbl... Just drop a label (or any control that support text/data
representation). For a control that displays text (like a textbox or label), just set the text property of the control to the value from the codebehind. For something like a checkbox or radiobutton, you'd set the checked property of the control based on the boolean value in the codebehind.
The Page_Load method should be placed in the code behind file. Since your
..aspx file inherits from the code behind it will have access to all the
fields of the code behind. Why do you need to access variables in your .aspx
file anyway? The whole point is not to mix the presentation from the
programmatic logic.
I think you should get a clear concept of code-behind. Place all your
controls in the .aspx file and event handlers in the code-behind file. From
the event handlers you can do your xml processing.
Did I answer your question or did I miss it altogether?
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:Ek***********************@twister.nyc.rr.com. .. OK, thats clear. But how do I reference the value of the codebehind.
lets say I have a codebehind object, that I instantiate in the aspx page within the pageload event like
void Page_Load(Object Src, EventArgs E) {
XMLManager xman = new XMLManager(); xman.ReadXML();
}
within the XMLManager class I have a
public String testStr;
which I set....how do I retrieve that value?
"Scott M." <s-***@BADSPAMsnet.net> wrote in message news:uN**************@TK2MSFTNGP12.phx.gbl... Just drop a label (or any control that support text/data
representation). For a control that displays text (like a textbox or label), just set the text property of the control to the value from the codebehind. For something like a checkbox or radiobutton, you'd set the checked property of the control based on the boolean value in the codebehind.
OK. that helps alot. Thanks!
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl... Don't think of it as "pulling" the value from the codebehind to the aspx page. Instead "push" the value from the codebehind to the aspx page.
In other words, you wouldn't need to grab the codebehind value testStr
from the aspx page. Instead, place a label (for example) on the aspx page and
in the Page_Load event of the codebehind place the string value in the label.
In the .aspx page:
<ASP:LABEL ID="lblDataHolder" RUNAT="Sever"></ASP:LABEL>
In the codebehind:
void Page_Load(Object Src, EventArgs E) {
XMLManager xman = new XMLManager(); xman.ReadXML();
//This takes the public string value in the class and places it into the label on the web page lblDataHolder.Text = xman.testStr;
}
I get what youre saying.
Im coming from a JSP background where it was fairly standard to instantiate
one or more helper objects in a JSP page. Then using those objects methods,
youd set variables on the page and populate the html with them. One really
common thing was to write some database connection class that returned a
resultSet and then loop through that to spit out a list of something in the
html.
Anyway...I guess whats confusing me is if I wanted to have several objects.
Say I needed to hit the db and email something on the same aspx page. I
write helper objects for the db and emailing. Then what do I do? place both
classes in one codebehind file? or can I access other cs files from my
codebehind file? Im used to writing one class per file, like in java.
thanks for your reply.
"Martha[MSFT]" <ma******@online.microsoft.com> wrote in message
news:ev**************@tk2msftngp13.phx.gbl... The Page_Load method should be placed in the code behind file. Since your .aspx file inherits from the code behind it will have access to all the fields of the code behind. Why do you need to access variables in your
..aspx file anyway? The whole point is not to mix the presentation from the programmatic logic. I think you should get a clear concept of code-behind. Place all your controls in the .aspx file and event handlers in the code-behind file.
From the event handlers you can do your xml processing.
Did I answer your question or did I miss it altogether?
Each codebehind is one class. But you could create your data class and
instantiate it and use it from your codebehind class.
Think of the codebehind as the programming logic for the web page. In that
logic, you can create instances of any other classes you want to get the job
done. The codebehind also provides a rich set of event handlers for the
controls place on the page as well as the page object itself.
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:s9****************@twister.nyc.rr.com... I get what youre saying.
Im coming from a JSP background where it was fairly standard to
instantiate one or more helper objects in a JSP page. Then using those objects
methods, youd set variables on the page and populate the html with them. One really common thing was to write some database connection class that returned a resultSet and then loop through that to spit out a list of something in
the html.
Anyway...I guess whats confusing me is if I wanted to have several
objects. Say I needed to hit the db and email something on the same aspx page. I write helper objects for the db and emailing. Then what do I do? place
both classes in one codebehind file? or can I access other cs files from my codebehind file? Im used to writing one class per file, like in java.
thanks for your reply.
"Martha[MSFT]" <ma******@online.microsoft.com> wrote in message news:ev**************@tk2msftngp13.phx.gbl... The Page_Load method should be placed in the code behind file. Since
your .aspx file inherits from the code behind it will have access to all the fields of the code behind. Why do you need to access variables in your .aspx file anyway? The whole point is not to mix the presentation from the programmatic logic. I think you should get a clear concept of code-behind. Place all your controls in the .aspx file and event handlers in the code-behind file. From the event handlers you can do your xml processing.
Did I answer your question or did I miss it altogether?
Excellent. that helps alot.
Thanks!
"Scott M." <s-***@BADSPAMsnet.net> wrote in message
news:OT**************@TK2MSFTNGP10.phx.gbl... Each codebehind is one class. But you could create your data class and instantiate it and use it from your codebehind class.
Think of the codebehind as the programming logic for the web page. In
that logic, you can create instances of any other classes you want to get the
job done. The codebehind also provides a rich set of event handlers for the controls place on the page as well as the page object itself.
"Karl Hungus" <nn*********@hotmail.com> wrote in message news:s9****************@twister.nyc.rr.com... I get what youre saying.
Im coming from a JSP background where it was fairly standard to
instantiate one or more helper objects in a JSP page. Then using those objects methods, youd set variables on the page and populate the html with them. One
really common thing was to write some database connection class that returned a resultSet and then loop through that to spit out a list of something in the html.
Anyway...I guess whats confusing me is if I wanted to have several objects. Say I needed to hit the db and email something on the same aspx page. I write helper objects for the db and emailing. Then what do I do? place both classes in one codebehind file? or can I access other cs files from my codebehind file? Im used to writing one class per file, like in java.
thanks for your reply.
"Martha[MSFT]" <ma******@online.microsoft.com> wrote in message news:ev**************@tk2msftngp13.phx.gbl... The Page_Load method should be placed in the code behind file. Since your .aspx file inherits from the code behind it will have access to all
the fields of the code behind. Why do you need to access variables in your
.aspx file anyway? The whole point is not to mix the presentation from the programmatic logic. I think you should get a clear concept of code-behind. Place all your controls in the .aspx file and event handlers in the code-behind file. From the event handlers you can do your xml processing.
Did I answer your question or did I miss it altogether?
Several people have given you answers that dance around the answer here, so
I'll give it to you straight: The CodeBehind class IS the page. Actually,
the Page Template INHERITS the CodeBehind class. So, the question is moot.
If data is in the CodeBehind class, it is already IN the Page.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:ud***********************@twister.nyc.rr.com. .. If I use a code behind class for an aspx page, what is the best way to get data from the codebehind class into my aspx page?
I know about databinding, but is there a more basic way of just
referencing the variables or calling getters?
thanks in advance
Thats very helpful to understand it that way.
I guess the thing for me is it seems like using codebehind is like an
include - which always seemed like faking it. Im used to doing the
separation on more of an object level...like I mentioned earlier, using
custom objects and then instantiating them within jsp -- more like
compositing instead of inhertance.
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:eT**************@TK2MSFTNGP10.phx.gbl... Several people have given you answers that dance around the answer here,
so I'll give it to you straight: The CodeBehind class IS the page. Actually, the Page Template INHERITS the CodeBehind class. So, the question is moot. If data is in the CodeBehind class, it is already IN the Page.
Understood. Inheritance is a very powerful aspect of OOP. When you inherit a
class in another class, the class which inherits becomes the other class.
Think of it like a basic car. Every car inherits "car" which means that it
has an engine, wheels, etc. Once you've created a new class that inherits
another, you can add properties to it, such as adding air conditioning to
the "car" class to create the "airconditioned car" class. The Page Template
inherits the CodeBehind class, which means that it IS the CodeBehind class.
The additional HTML and other code in the Template are like the air
conditioning - part of the derived class which doesn't exist in the base
class. Incidentally, the CodeBehind class inherits System.Web.UI.Page, which
makes it a Page with extra stuff added as well.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Karl Hungus" <nn*********@hotmail.com> wrote in message
news:7F****************@twister.nyc.rr.com... Thats very helpful to understand it that way.
I guess the thing for me is it seems like using codebehind is like an include - which always seemed like faking it. Im used to doing the separation on more of an object level...like I mentioned earlier, using custom objects and then instantiating them within jsp -- more like compositing instead of inhertance.
"Kevin Spencer" <ke***@takempis.com> wrote in message news:eT**************@TK2MSFTNGP10.phx.gbl... Several people have given you answers that dance around the answer here, so I'll give it to you straight: The CodeBehind class IS the page.
Actually, the Page Template INHERITS the CodeBehind class. So, the question is
moot. If data is in the CodeBehind class, it is already IN the Page.
inheritance is the less of the two, compared with compositing. Most design
patterns are based on composites rather than inheritance.
I would rather have my page be "composed of" than "is a" relationship. http://www.javaworld.com/jw-11-1998/...echniques.html
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:uY**************@tk2msftngp13.phx.gbl... Understood. Inheritance is a very powerful aspect of OOP. When you inherit
a class in another class, the class which inherits becomes the other class. Think of it like a basic car. Every car inherits "car" which means that it has an engine, wheels, etc. Once you've created a new class that inherits another, you can add properties to it, such as adding air conditioning to the "car" class to create the "airconditioned car" class. The Page
Template inherits the CodeBehind class, which means that it IS the CodeBehind
class. The additional HTML and other code in the Template are like the air conditioning - part of the derived class which doesn't exist in the base class. Incidentally, the CodeBehind class inherits System.Web.UI.Page,
which makes it a Page with extra stuff added as well.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Karl Hungus" <nn*********@hotmail.com> wrote in message news:7F****************@twister.nyc.rr.com... Thats very helpful to understand it that way.
I guess the thing for me is it seems like using codebehind is like an include - which always seemed like faking it. Im used to doing the separation on more of an object level...like I mentioned earlier, using custom objects and then instantiating them within jsp -- more like compositing instead of inhertance.
"Kevin Spencer" <ke***@takempis.com> wrote in message news:eT**************@TK2MSFTNGP10.phx.gbl... Several people have given you answers that dance around the answer
here, so I'll give it to you straight: The CodeBehind class IS the page. Actually, the Page Template INHERITS the CodeBehind class. So, the question is moot. If data is in the CodeBehind class, it is already IN the Page.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: A.M |
last post by:
Hi,
Using VS.NET 2003, If i use SRC page attribute instead of CodeBehind, do i
still have intelisence and generally IDE support for that?
Thanks,
Ali
|
by: jm |
last post by:
I have a question about codebehind. I have an upload namespace, class
and all in a codebehind. I currently have it so it works with one of
my .aspx pages. I want to use it for another .aspx...
|
by: Rob Shorney |
last post by:
Hi,
I am using .Net 2003 , c# asp.net.
The situation i have is this. I have a asp.net page which in the codebehind
maintains an xml document in memory. The user can click on a button to popup
a...
|
by: Thomas Andersson |
last post by:
Hi all,
I've been thinking of about adding new languages to our website and is
currently investigating how this could be done. And I know that one way to go
would be to create new aspx-pages...
|
by: Randall Parker |
last post by:
Using VS 2003 and Cassini web server. I'm new to ASP.Net and so this may be a dumb
question.
I'm getting an error where the type 'FarmLand.WebForm1' is not found. The Codebehind
C# source file...
|
by: WT |
last post by:
Hello,
I am searching for a way to generate automatically from codebehind the
<!Doctype....for asp.net pages using .net 3.5 c# and vs2008.
Subidiary question: if I do a server transfert in my...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
| |