How to pass value from locally to globally

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2007
Posts: 19
Reputation: ruhi is an unknown quantity at this point 
Solved Threads: 0
ruhi ruhi is offline Offline
Newbie Poster

How to pass value from locally to globally

 
0
  #1
Jun 26th, 2007
Hi all,
Can any one tell me how to use a value generated through a button click event in another button click event in the same page.Is viewstate is helpful? If yes then how?
-ruhi
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 30
Reputation: sibir1us is an unknown quantity at this point 
Solved Threads: 2
sibir1us's Avatar
sibir1us sibir1us is offline Offline
Light Poster

Re: How to pass value from locally to globally

 
0
  #2
Jun 26th, 2007
Hm, how about hidden fields?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 19
Reputation: ruhi is an unknown quantity at this point 
Solved Threads: 0
ruhi ruhi is offline Offline
Newbie Poster

Re: How to pass value from locally to globally

 
0
  #3
Jun 27th, 2007
How to use Hidden Fields ? Can you explain...
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 30
Reputation: sibir1us is an unknown quantity at this point 
Solved Threads: 2
sibir1us's Avatar
sibir1us sibir1us is offline Offline
Light Poster

Re: How to pass value from locally to globally

 
0
  #4
Jun 27th, 2007
Hidden fields are not displayed by the browser, there are a number of uses for them. When dealing with forms you will usually find yourself using some sort of database mechanism: MySQL, SQL Server, or maybe justa plain text file. In any case use hidden forms to pass along information to your database that may have already been received from the user. In this rare case, a hidden form field may come in handy.

A hidden HTML field is used to pass along variables w/ values from one form to another page without forcing the user to re-enter the information. Use the type attribute to specify a hidden field.

  1. <input type="hidden" />

There is no display of your hidden field in the box because the browser is told to hide them from view. Our field above is incomplete and pretty much useless as it is. Adding a name and a value attribute will change this.

Naming your fields can be accomplished in two different ways discussed previously. Use the id or name attribute to specify a name for your hidden field.

  1. <input type="hidden" id="age" name="age" value="23" />
  2. <input type="hidden" id="DOB" name="DOB" value="01/01/70" />
  3. <inpyt type="hidden" id="admin" name="admin" value="1" />

Above we have demonstrated 3 possible hidden fields that you may want to pass along some form at some point, especially if you have any kind of user base where returning users must log in. The admin field could be used to check some sort of user level entry of a returning user; 1 being administrator and 0 being non-administrator access.

Use hidden fields when you have variables you want to pass from one form to another without forcing the user to re-type information over and over again.

This tutorial is available from www.tizag.com

**********

15 minutes of research can save you 50% or more. forum.feodorgeorgiev.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 19
Reputation: ruhi is an unknown quantity at this point 
Solved Threads: 0
ruhi ruhi is offline Offline
Newbie Poster

Re: How to pass value from locally to globally

 
0
  #5
Jun 27th, 2007
Thanks for your reply,But what i really want is..
Let me explain..
I declare a global variable say flag which is boolean.Then i am assigning true value on button click event of button say Add and on Edit the value of flag is false. Now I want to use value of flag in another button click event say button Save.But the value is not passing from Add Button to Save Button.
I tried using hidden values but not getting then also.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 30
Reputation: sibir1us is an unknown quantity at this point 
Solved Threads: 2
sibir1us's Avatar
sibir1us sibir1us is offline Offline
Light Poster

Re: How to pass value from locally to globally

 
0
  #6
Jun 27th, 2007
What environment are you using? .NET and C#? Could you straighten your metacode a bit, so i can understand where exactly are you going with it? Give me the whole picture - purpose of the page, and what are your business rules for the page. Once we have this, i can easily help you solve your problem.
******************
15 minutes of research can save you 50% or more. forum.feodorgeorgiev.com

***Need Web Hosting?
******************
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 19
Reputation: ruhi is an unknown quantity at this point 
Solved Threads: 0
ruhi ruhi is offline Offline
Newbie Poster

Re: How to pass value from locally to globally

 
0
  #7
Jun 28th, 2007
I am using Visual Studio .net 2003.
There is a form containing many buttons like add, save, edit, delete,undo,find and four more buttons which fetch the data like on button << it will show first data from database.On >> this button it will show last data of database, on < it will show previous data of the exsting showing data and > will show next data of the existing.
Now what I want to do is on clicking add button all controls will come in enable mode so user can write in textboxes for adding a new data, then on clicking save it will add to database and similarly on clicking edit the data which the form is showing will allow user to edit and on clicking save it will be edited in database. But now question is how save button will identify that adding will be done or editing,So I declared a global variable say flag which is boolean. Now on clicking add button flag will be true and on edit it will have value false. But the value is not retained by the flag.So how to retain the value of flag so it can be used by the save button.If you have any idea than tell..
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 18
Reputation: NET-Developer is an unknown quantity at this point 
Solved Threads: 1
NET-Developer NET-Developer is offline Offline
Newbie Poster

Re: How to pass value from locally to globally

 
0
  #8
Jun 29th, 2007
Viewstate is helpful when you remain within one page (including when you return there by postback). But it is destroyed when you are leaving the page.

in first click processing method you store your value to viewstate
Viewstate["myValue"] = someValue (may be any type)

in the second click processing method you read your value
MyType someValue = (MyType)Viewstate["myValue"];
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 30
Reputation: sibir1us is an unknown quantity at this point 
Solved Threads: 2
sibir1us's Avatar
sibir1us sibir1us is offline Offline
Light Poster

Re: How to pass value from locally to globally

 
0
  #9
Jun 29th, 2007
save and edit is the same thing, no? Why cant you do the appropriate checks on the sql server side?
Last edited by sibir1us; Jun 29th, 2007 at 1:14 pm.
******************
15 minutes of research can save you 50% or more. forum.feodorgeorgiev.com

***Need Web Hosting?
******************
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 19
Reputation: ruhi is an unknown quantity at this point 
Solved Threads: 0
ruhi ruhi is offline Offline
Newbie Poster

Re: How to pass value from locally to globally

 
0
  #10
Jun 30th, 2007
Hi,
Really Viewstate worked.
It is retaining value in the same page as I was needing.
Thank you both of u
-Ruhi
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC