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

Hm, how about hidden fields?

How to use Hidden Fields ? Can you explain...

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.

<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.

<input type="hidden" id="age" name="age" value="23" />
<input type="hidden" id="DOB" name="DOB" value="01/01/70" />
<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

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.

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.

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..

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"];

save and edit is the same thing, no? Why cant you do the appropriate checks on the sql server side?

Hi,
Really Viewstate worked.
It is retaining value in the same page as I was needing.
Thank you both of u
-Ruhi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.