473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

CS0103: The name 'pm' does not exist in the current context

I am passing an Object using Session from one form to other.
pm.a = a;
pm.b = b;
e.g. Session["master"] = pm;

OK, it passes and i receive it another form. at second form, I received it on Page Load
Master master = new Master();
Page_Load
{
pm = (Master)Session["master"];
}
protected void btnSubmitPolicy_Click(object sender, EventArgs e)
{
pm.c = c;
}

I declared pm at top of Class.
Now i want to add more properties in pm object. but under Submit_click...

Problem is that , pm initializes at each post back and clears initial values. I dont want to trust on Session thats why I need to get Session values in object when 1st time page Loads...

Please Help.
Jan 16 '08 #1
3 3534
Frinavale
9,735 Expert Mod 8TB

Problem is that , pm initializes at each post back and clears initial values. I dont want to trust on Session thats why I need to get Session values in object when 1st time page Loads...

Please Help.
Use the isPostBack Page property to determine whether or not it is the first time the user visits the page.

For example, to check if it's the first time visiting use something like:

Expand|Select|Wrap|Line Numbers
  1. If IsPostBack = False Then
  2.     'This is the first time the user has visited the page
  3. End If
  4.  
-Frinny
Jan 16 '08 #2
I am not satisfy withthe answer...

Basically Variable resets every time when Page refresh...
Jan 22 '08 #3
Frinavale
9,735 Expert Mod 8TB
I dont want to trust on Session thats why I need to get Session values in object when 1st time page Loads...
What do you mean by this?
Why don't you want to "trust" what's in Session?


If you want to get values of an object "When its the First Time the Page Loads" you do this:
Expand|Select|Wrap|Line Numbers
  1. Master pm;
  2. Page_Load
  3. {  if( isPostBack == false)
  4.     {
  5.         pm = (Master)Session["master"];
  6.     }
  7. }


But that is not your problem.
Your problem is that you are not saving the changes to your object in the Button Click event code....

Since you are changing the state of your object in the Button Click event (setting more of the object's properties), you need to re-save that object in session in order to retain the "new values".

If you do not re-save your object, it will appear as if the object is "reset".
The reason is quite simply because it is reset...since you didn't save your changes.

Expand|Select|Wrap|Line Numbers
  1. Master pm;
  2. Page_Load
  3. {  
  4.     pm = (Master)Session["master"];
  5. }
  6. protected void btnSubmitPolicy_Click(object sender, EventArgs e)
  7. {   //what is c? has it been declared somewhere? are you sure it's being set properly?
  8.     pm.c = c;
  9.     Session["master"] = pm;
  10. }
Oh yeah, also, you have not declared a variable named "pm"...you need to declare one in order to use it.

You need to change
Expand|Select|Wrap|Line Numbers
  1. Master master;
  2. Page_Load{//...
  3.  
To
Expand|Select|Wrap|Line Numbers
  1. Master pm;
  2. Page_Load{//...
  3.  
Otherwise you do not have a Master object variable named "pm" to use in your code.

-Frinny
Jan 22 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html>...
6
by: CuriousGeorge | last post by:
I've upgraded a .Net 1.1 web app to 2.0 and am having a heck of a time getting resources to work again. From what I understand if I move my strings.resx file into the App_GlobalResources folder I...
3
by: Eric | last post by:
I get following errors under C# The name 'txtName' does not exist in the current context The name 'txtName' does not exist in the current context This is a nightmare. I have my web user control...
3
by: Michael | last post by:
Hi, I am getting a strange error. Last night when I left work this was working perfectly. This morning when I try to run this code in VS2005, it comes up with an error saying "The name 'UserName'...
3
by: gdubois | last post by:
Hi!! I am trying for the first time to put on our intranet a really basic ASP.NET page, using VS2003 and C#. It's a page reading some info from an ACCESS database, using one dataset...
2
by: weird0 | last post by:
When i am working on client side of a webservice, where i add a reference to it(have written the function CheckPincode inside the webservice), the compiler says: the name CheckPincode does not...
5
by: nudrat | last post by:
I included a control TextBox with 'txtError' name. whenever I build this I get this error. The name 'txtError' does not exist in the current context But its running on last successful Build. I...
1
by: avecreep | last post by:
Hi, i was trying to find a web application and i found one open source on the internet. i put the code folders on the root folder and when i tried to acces via web browser it all worked fine ( i...
0
by: Terry | last post by:
Hello, I have problem adding controls to my webpage default.aspx. There is a group of controls that just refuse to be used with message: 'The name 'controlname' does not exist in the current...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.