943,982 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 2771
  • ASP.NET RSS
Jun 26th, 2007
0

How to pass value from locally to globally

Expand Post »
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
Reputation Points: 23
Solved Threads: 1
Light Poster
ruhi is offline Offline
25 posts
since Jun 2007
Jun 26th, 2007
0

Re: How to pass value from locally to globally

Hm, how about hidden fields?
Reputation Points: 10
Solved Threads: 2
Light Poster
sibir1us is offline Offline
30 posts
since Jun 2007
Jun 27th, 2007
0

Re: How to pass value from locally to globally

How to use Hidden Fields ? Can you explain...
Reputation Points: 23
Solved Threads: 1
Light Poster
ruhi is offline Offline
25 posts
since Jun 2007
Jun 27th, 2007
0

Re: How to pass value from locally to globally

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.

ASP.NET Syntax (Toggle Plain Text)
  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.

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 2
Light Poster
sibir1us is offline Offline
30 posts
since Jun 2007
Jun 27th, 2007
0

Re: How to pass value from locally to globally

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.
Reputation Points: 23
Solved Threads: 1
Light Poster
ruhi is offline Offline
25 posts
since Jun 2007
Jun 27th, 2007
0

Re: How to pass value from locally to globally

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.
Reputation Points: 10
Solved Threads: 2
Light Poster
sibir1us is offline Offline
30 posts
since Jun 2007
Jun 28th, 2007
0

Re: How to pass value from locally to globally

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..
Reputation Points: 23
Solved Threads: 1
Light Poster
ruhi is offline Offline
25 posts
since Jun 2007
Jun 29th, 2007
0

Re: How to pass value from locally to globally

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"];
Reputation Points: 10
Solved Threads: 1
Newbie Poster
NET-Developer is offline Offline
18 posts
since May 2007
Jun 29th, 2007
0

Re: How to pass value from locally to globally

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.
Reputation Points: 10
Solved Threads: 2
Light Poster
sibir1us is offline Offline
30 posts
since Jun 2007
Jun 30th, 2007
0

Re: How to pass value from locally to globally

Hi,
Really Viewstate worked.
It is retaining value in the same page as I was needing.
Thank you both of u
-Ruhi
Reputation Points: 23
Solved Threads: 1
Light Poster
ruhi is offline Offline
25 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

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: Time setting
Next Thread in ASP.NET Forum Timeline: Google Checkout





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


Follow us on Twitter


© 2011 DaniWeb® LLC