| | |
problem with variables
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 24
Reputation:
Solved Threads: 0
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
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
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:
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,
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)
#region Change Variable string changevalue = string.Format("javascript:document.getElementById('{0}').value = {1}.options[{1}.selectedIndex].value;", hiddenfield1.ClientID, dropdownlist1.ClientID); dropdownlist1.Attributes.Add("onChange", changevalue); #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,
Delphi & C# programmer deluxe...
![]() |
Similar Threads
- my sql problem (PHP)
- (Newbie question) Variable problem (Assembly)
- How to send js variables with a ajax request (JavaScript / DHTML / AJAX)
- Variables inside methods and type errors (Python)
- Trouble with module-scope variables (Python)
- Dynamic Array of Structures, Loop problem! (C++)
- Problem with variables in Windows shell script (Windows NT / 2000 / XP)
- Double parsing variables? (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: how to save an image into database
- Next Thread: c# with dot net
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox class click commonfunctions control countryselector dataaccesslayer database datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





