hidden field options

G

Guest

Hello All:

I have two webforms (WebForm1.aspx and WebForm2.aspx) that inherit from a
base class called BasePage.aspx. BasePage.aspx has no user interface but
inherits System.Web.UI.Page (BasePage performs security checks in the
Page_Load ... Handles MyBase.Load event). BasePage also has a hidden field
(hdnSessionId) that I want to use to cache a sessionId (client requirement).
I can not use Session, ViewState or QueryString to cache this value (client
requirement).

Here's my question: How do I reference hdnSessionId from within
WebForm1.aspx and WebForm2.aspx? I'm pretty sure that I can do this.
hdnSessionId is in WebFrom1's parent class.

I'm sure that this is somewhat straightforward. I'm also sure that it
involves the MyBase.Controls collection. I'm just not sure how to proceed
when drilling upward in lieu of drilling downward when looking for a control.

Any help would be appreciated.

TIA,
 
G

George Ter-Saakov

Your question is not clear.

It should work as you described it.
If BasePage.aspx defines
protected HiddenField f;

you should be able to reference it in the WebForm1 and WebForm2.
the only thing is that you must have in both pages in HTML the hidden field
with id=f;


PS: you might look at RegisterHiddenField method of the page to automaticly
insert hidden field into HTML.

George
 
G

Guest

Hi George,

Please see below.
--
Joe


George Ter-Saakov said:
Your question is not clear.
Let em rephrase my question: how do I reference a control in a parent form
from within the child form if child form inherits parent form?
It should work as you described it.
If BasePage.aspx defines
protected HiddenField f; I've got this.

you should be able to reference it in the WebForm1 and WebForm2.
the only thing is that you must have in both pages in HTML the hidden field
with id=f;
I don't understand this. Would you please re-explain?
PS: you might look at RegisterHiddenField method of the page to automaticly
insert hidden field into HTML.
I will look at this.
 
G

George Ter-Saakov

The ASP.NET automatically "connects" member variable of your class to
instances of the object that represent that HTML field (with runat=server
set).

So if you have a member variable

protected HtmlInputHidden myVariable;

and in your HTML you have
<input type="hidden" id="myVariable" runat=server>
then ASP.NET will automatically create an object with type HtmlInputHidden
and assign it to variable myVariable. And it will represent the HTML code
<input type....>


So if you have in BasePage class defined hidden variable (it must be
declared as protected) myVariable you must have corresponding HTML
<input type="hidden" id="myVariable" runat=server>
in the HTML of WebForm1 and WebForm2



George.
 
G

Guest

Thanks George.

So your saying that ASP.NET will automatically connect the hidden field in
the base page with the hidden fields in the child pages if they have the same
HTML declarations?

Did I get that right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top