My source to my test is below. I am trying to figure out state. I
create a int and a Test object and set them to some value on
Page_Load. When I click my button on my web page, Button1_Click gets
called but a = 0 and objTest.Name is null. Now it does make sense than
when the button is clicked, that a should be 0 and objTest should be
null but I thought that ASP.NET took care of this. Do I have to go
back to old ASP days and set this stuff to Application("ob jTest") =
objTest???? There must be a better way. Please enlighten me....
_______________ _______________ _______________ _______________ _______________ _
My Test Class...
public class Test
{
public Test()
{
//
// TODO: Add constructor logic here
//
}
private string strName;
public string Name
{
get { return strName; }
set { strName = value; }
}
My ASP.NET PAGE
public class WebForm1 : System.Web.UI.P age
{
protected System.Web.UI.W ebControls.Butt on Button1;
public Test objTest;
public int a;
private void Page_Load(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
objTest = new Test();
objTest.Name = "test";
a = 10;
}
}
private void Button1_Click(o bject sender, System.EventArg s e)
{
a = 199;
objTest.Name = "a";
}
}
Thanks
Ralph Krausse www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg 2 1071
Ralph Krausse wrote: My source to my test is below. I am trying to figure out state. I create a int and a Test object and set them to some value on Page_Load. When I click my button on my web page, Button1_Click gets called but a = 0 and objTest.Name is null. Now it does make sense than when the button is clicked, that a should be 0 and objTest should be null but I thought that ASP.NET took care of this. Do I have to go back to old ASP days and set this stuff to Application("ob jTest") = objTest???? There must be a better way. Please enlighten me....
_______________ _______________ _______________ _______________ _______________ _
My Test Class...
public class Test { public Test() { // // TODO: Add constructor logic here // }
private string strName; public string Name { get { return strName; } set { strName = value; } }
My ASP.NET PAGE
public class WebForm1 : System.Web.UI.P age { protected System.Web.UI.W ebControls.Butt on Button1; public Test objTest; public int a; private void Page_Load(objec t sender, System.EventArg s e) { if(!IsPostBack) { objTest = new Test(); objTest.Name = "test"; a = 10; } }
private void Button1_Click(o bject sender, System.EventArg s e) { a = 199; objTest.Name = "a"; } }
Each request is serviced by a new Page instance. If Test is supposed to
maintain state across postbacks, you have to store it somewhere else, e.g.
SessionState or ViewState.
Cheers,
--
Joerg Jooss jo*********@gmx .net
Hi Ralph,
An ASP.Net Page is really no different "under the covers" than an ASP page.
That is, it exists and works in the context of an HTTP request, which is
stateless. Just as an ASP page, the entire Page class has to be
reconstructed with each request, or PostBack. Now, also note that the Page
class has a number of built-in Event Handlers, which you can override to add
your own code to the Page execution. These Event Handlers fire in a certain
sequence (se http://msdn.microsoft.com/library/de...nLifecycle.asp
for details). The Page_Load Event Handler fires BEFORE the Events are
handled. Hard to handle an Event if the class it refers to doesn't exist
yet, eh?
Following me so far? Okay, so in your Page_Load Event Handler, you create an
instance of your "Test" class. You do NOT create an instance of it if the
Page is Posted Back. Now, your Event Handler for the Button click tries to
assign a value to its members. However, as it doesn't exist, it throws an
exception because the Test class instance doesn't exist. Where you're seeing
"a" as being 0, I don't know. I can only guess that you're checking before
the value is assigned in the Button click Event handler.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Ralph Krausse" <go*******@cons iliumsoft.com> wrote in message
news:49******** *************** ***@posting.goo gle.com... My source to my test is below. I am trying to figure out state. I create a int and a Test object and set them to some value on Page_Load. When I click my button on my web page, Button1_Click gets called but a = 0 and objTest.Name is null. Now it does make sense than when the button is clicked, that a should be 0 and objTest should be null but I thought that ASP.NET took care of this. Do I have to go back to old ASP days and set this stuff to Application("ob jTest") = objTest???? There must be a better way. Please enlighten me....
_______________ _______________ _______________ _______________ _______________ _ My Test Class...
public class Test { public Test() { // // TODO: Add constructor logic here // }
private string strName; public string Name { get { return strName; } set { strName = value; } }
My ASP.NET PAGE
public class WebForm1 : System.Web.UI.P age { protected System.Web.UI.W ebControls.Butt on Button1; public Test objTest; public int a; private void Page_Load(objec t sender, System.EventArg s e) { if(!IsPostBack) { objTest = new Test(); objTest.Name = "test"; a = 10; } }
private void Button1_Click(o bject sender, System.EventArg s e) { a = 199; objTest.Name = "a"; } } Thanks Ralph Krausse
www.consiliumsoft.com Use the START button? Then you need CSFastRunII... A new kind of application launcher integrated in the taskbar! ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Aamir |
last post by:
Hi,
Quick Question:
How to create a simple XML with US States list and read it into a
combo box.
Detail:
I am very new to Dot Net technology as well as xml.
I am building a desktop app in C# and need to populate the US States
list (AL, AR, .. WY) in a combo box. I could have done it by reading
|
by: jm |
last post by:
Easy probably, please read on. I know some of you have commented
already about some of my socket question. I appreciate that.
I have a Form1:
static void Main()
{
Application.Run(new Form1());
clsListening.AsynchronousSocketListener.StartListening();
|
by: Hazzard |
last post by:
I just realized that the code I inherited is using all asp.net server
controls (ie. webform controls) and when I try to update textboxes on the
client side, I lose the new value of the textbox when submitting the form to
update the database. The server doesn't have the client side value any more.
It seems to me that as I begin to write the client side javacript code for
form validation and client side editing capabilities in order to save...
|
by: Steven |
last post by:
Hello,
First, let me state that I am trying to learn asp.net, so I am a beginner.
Now on to the issue. I have a webform with a single Textbox and a
FileSystemWatcher monitoring a directory for OnCreate events. I am trying
to change the text in response to an OnCreate event. I would like to change
the Forecolor to red, from black. Apparently, this is not as easy to do as
in vb.net. I have tried the direct approach in the OnCreate...
|
by: jason |
last post by:
we have developed a .NET class library that defines a family of
reusable business objects. the class library is developed in C#, and
works quite well.
one problem, however, is that as more and more applications are being
developed to consume this class library, we are running into deployment
and version controll issues.
i recall a lot of this kind of thing being solved with distributed
application models, such as the EJB...
| |
by: Brian Elmegaard |
last post by:
Hi,
I am struggling to understand how to really appreciate object
orientation. I guess these are FAQ's but I have not been able to find
the answers. Maybe my problem is that my style and understanding are
influenced by matlab and fortran.
I tried with the simple example below and ran into several questions:
1: Why can't I do:
def __init__(self,self.x):
|
by: Shawnk |
last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the
Enum class (relative to boolean operations).
If this is true then (thus and therefore) you can not design state machines in
C# where the machine can use the enumerated 'state' to execute (thus the term
'machine' as in 'state machine') the machine operations as this requires
boolean operations to be performed on the state.
.....
|
by: bartonc |
last post by:
#Boa:Dialog:DBConnectDialog
import wx
##"""Given a set if login specs, create a dbServer instance and
## ensure that there is a valid, open connection to the database.
## If not, set the dbConnect to None.
## spec: dict(UserName=name, Password=pswd, ServerName=host)
## Allow names to be set with Default Holder. Consiter Dictionary
## or even a tuple? (name, pswd, host)"""
|
by: Dragan |
last post by:
Hi,
We're working in VS 2005, Team edition, if it makes any difference at
all (should be up-to-date and all that, but could not guarantee it is
100%).
We've implemented a simple generic wrapper parser under C++/CLI. It's
a basic project created under Visual C++/CLR - Class Library - and
it's pretty much what it is, just one /clr compiled class, fully CLR,
no C++ native types or processing, nothing, just managed all the way.
The reason...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |