Need help with accessing control in inherited form

G

Guest

Hello All:

I have two webforms (WebForm1.aspx and WebForm2.aspx) that inherit from
BasePage.aspx. BasePage.aspx inherits System.Web.UI.Page and has one hidden
field (hdnSessionId) that I want to use to cache a value that the web app
needs. I can not use Session, ViewState or QueryString to cache this value
(client requirement). The hidden field is dimmed in the BasePage.aspx.vb
code-behind as Protected WithEvents hdnFormSessionId As
System.Web.UI.HtmlControls.HtmlInputHidden.

Here's my question: How do I reference hdnSessionId from within
WebForm1.aspx and WebForm2.aspx (the child forms that inherit BasePage.aspx)?

Any help would be appreciated.

TIA,
 
K

Karl Seguin [MVP]

If it's protected, you should be able to reference it simply by name.
Protected members, unlike private ones, are available to child-class (the
point of protected).

Karl
 
G

Guest

Hi Karl,

Maybe you can help me understand something:

In BasePage.aspx I have an hidden field defined in the HTML as

<INPUT id="hdnSessionId" type="hidden" name="hdnSessionId" runat="server">.

I have an idetical declaration in WebForm1.aspx's HTML.

In BasePage,aspx's code-behind I have declared Protected WithEvents
hdnFormSessionId As System.Web.UI.HtmlControls.HtmlInputHidden. There is no
such declaration in WebForm1.aspx's code-behind.

When I run the code and populate WebForm1.aspx's hidden field, I see the
same value in BasePage.aspx's hidden field (checking with
Ctype(MyBase.FindControl("Form1").FindControl("hdnSessionId"),
HtmlInputHidden).Value in the immediate window). But I see the value without
explicitly populating the hidden field in BasePage.aspx. I don't understand
this.

Do you understand this? Why would I see this behavior?
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top