Hidden field?

  • Thread starter Thread starter Yatin Bhuta
  • Start date Start date
Y

Yatin Bhuta

Hi,

I have WebPage1 which has a link to go to WebPage2. This link passes a value
to WebPage2. In the page_load event I get this value using
Request.QueryString and put it in a public data member of WebPage 2.
WebPage2 has a button on it and when this button is clicked the page is
posted back to the server.

My question is when the page is posted back to the server do I still have
the value that was passed from WebPage1 (Which I had stored in the public
datamember). If it's not then, I guess I will have to use hidden box and if
that's the case then, what is the syntax for creating a hidden text box?

Also, if this WebPage1 creates a datatable in dataset then, can this
datatable be used in WebPage2. If yes then, how?

Thanks

Yatin
 
-----Original Message-----
Hi,

I have WebPage1 which has a link to go to WebPage2. This link passes a value
to WebPage2. In the page_load event I get this value using
Request.QueryString and put it in a public data member of WebPage 2.
WebPage2 has a button on it and when this button is clicked the page is
posted back to the server.

My question is when the page is posted back to the server do I still have
the value that was passed from WebPage1 (Which I had stored in the public
datamember).

No. You only have it when the page first loads. When you
post back a new instance of your page is created so you
loose the value in your property.

If it's not then, I guess I will have to use hidden box
and if
that's the case then, what is the syntax for creating a
hidden text box?

<asp:textbox id="txtHidden" visible="false"
runat="server" />
Also, if this WebPage1 creates a datatable in dataset then, can this
datatable be used in WebPage2. If yes then, how?

This is possible. You could put the datatable in the pages
Context.Items collection, and do a Server.Transfer to
WebPage2.

However you may want to rethink your design, it's not a
good idea to be passing tables around in the request.
 
If you need to persist the data between page postback you can also put
it in the ViewState.

Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
 
First question:
Hidden Field: When your WebPage2 is loading, in the pageload event
write this line of code to register a hidden variable and set a value
for it.
RegisterHiddenField("VariableName", VariableValue)
During the post back you can get back the value using
Request.Form("VariableName")

Second question:
After the code behind page is completed processing all your variables,
objects created in the page will be no longer available for you to
use. Because they have only Page level scope. If you want to create an
object in one page and want to use that in another page, there are
many ways to do it. You store that object in Session or Application,
Cache or Static(shared) variable, then you can access them in other
pages. Application and Cache also will work similar to static
variables and you will have only one instance of them for all the
users. If you want to have different objects for different users, you
need to use a session variable.
 
Back
Top