943,685 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 465
  • ASP.NET RSS
Aug 29th, 2009
0

problem with variables

Expand Post »
Hi,

I have some problem with using variables, I am making a form in C#?asp.net .

Now in my web application form I am having two controls on web page (dropdown, button); depending on the selection in the dropdown I have changed some value in a integer variable.

PROBLEM: the variable retains this value until the event ends.

after that I am using this value to do some processing; it is here that I find that the int value has changed back to 0(its default value). How can I prevent this as I need the value of the int?

I have tried my code both by declaring the int variable as global to that form and also by declaring it inside that particular event.

can someone please help me?

thank You
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
shankbond is offline Offline
31 posts
since Jun 2009
Aug 29th, 2009
0

Re: problem with variables

Try using PostBack property...Write ure code maybe then we can give u suggestions..
Reputation Points: 8
Solved Threads: 13
Junior Poster
anuj576 is offline Offline
180 posts
since Jul 2008
Aug 30th, 2009
0

Re: problem with variables

Hi,

i have encountered similar problems in the past as well, please tell me wether you are using this variable within your JS or ASP CS code.

i would like to share with you one handy dandy control - the Hidden Field.

You could change the hidden field value with JavaScript like this:

JavaScript Syntax (Toggle Plain Text)
  1. #region Change Variable
  2. string changevalue = string.Format("javascript:document.getElementById('{0}').value = {1}.options[{1}.selectedIndex].value;", hiddenfield1.ClientID, dropdownlist1.ClientID);
  3. dropdownlist1.Attributes.Add("onChange", changevalue);
  4. #endregion

You can place that code within your formload - PS this cannot be within the

if(!Page.isPostback)
{}

else you will get errors later.

-----------

now what you want is that variable

INT myVariable = int.parse(hiddenfield1.value.Tostring());

Boom.

This variable myVariable should be global, and thus the value can change constantly over multiple events.

if you require this variable to be used cross postback, add it to a session :

session["MyVariable"] = myVariable.Tostring();

or in the querystring :

response.redirect(string.Format("Mypage?variable={0}", myVariable));

Hope this helps.

Regards,
cVz
Reputation Points: 29
Solved Threads: 7
Junior Poster
cVz is offline Offline
139 posts
since Mar 2008
Aug 31st, 2009
0

Re: problem with variables

post the code..
Reputation Points: 28
Solved Threads: 106
Banned
dnanetwork is offline Offline
633 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how to save an image into database
Next Thread in ASP.NET Forum Timeline: c# with dot net





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC