Request.Form with Masterpage

  • Thread starter Thread starter sck10
  • Start date Start date
S

sck10

Hello,

How do you use Request.Form["HiddenField"] when the first page is using a
MasterPage?

Thanks, sck10
 
Hello Steve,

Do you mean in the original page, the hidden fields are put on MasterPage's
content? If so, this does make the identification of the hidden
fields(form items) in target page abit difficult. Becaue for controls put
in Master page, its name and id will be mangled. For example, the following
html control in master page

=========
<input id="hidden1" name="hidden1" runat="server" type="hidden"
value="hidden1 value" />
<input id="hidden2" name="hidden2" runat="server" type="hidden"
value="hidden2 value" />
===========

will be rendered as below finally:

<input name="ctl00$hidden1" type="hidden" id="ctl00_hidden1"
value="hidden1 value" />
<input name="ctl00$hidden2" type="hidden" id="ctl00_hidden2"
value="hidden2 value" />

Thus, on the target page, you can not directly use the original
hiddenfield's name to quey the Request.Form collection. One flexible means
is to query the Request.Form collection and find the one that contains the
hiddenfield's unmangled name. e.g.

========in target page===============

protected void Page_Load(object sender, EventArgs e)
{


foreach (string key in Request.Form.Keys)
{
if(key.Contains("hidden1"))
Response.Write("<br/>" + key + ": " + Request.Form[key]);
}
}
==============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,
Becaue for controls put in Master page, its name and id will be mangled.

.... which you can work around by using the .ClientID-property.

Cheers,
Olaf
 
Thanks Walter, I will try your suggestion.



Steven Cheng said:
Hello Steve,

Do you mean in the original page, the hidden fields are put on
MasterPage's
content? If so, this does make the identification of the hidden
fields(form items) in target page abit difficult. Becaue for controls put
in Master page, its name and id will be mangled. For example, the
following
html control in master page

=========
<input id="hidden1" name="hidden1" runat="server" type="hidden"
value="hidden1 value" />
<input id="hidden2" name="hidden2" runat="server" type="hidden"
value="hidden2 value" />
===========

will be rendered as below finally:

<input name="ctl00$hidden1" type="hidden" id="ctl00_hidden1"
value="hidden1 value" />
<input name="ctl00$hidden2" type="hidden" id="ctl00_hidden2"
value="hidden2 value" />

Thus, on the target page, you can not directly use the original
hiddenfield's name to quey the Request.Form collection. One flexible means
is to query the Request.Form collection and find the one that contains the
hiddenfield's unmangled name. e.g.

========in target page===============

protected void Page_Load(object sender, EventArgs e)
{


foreach (string key in Request.Form.Keys)
{
if(key.Contains("hidden1"))
Response.Write("<br/>" + key + ": " + Request.Form[key]);
}
}
==============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
Thanks for your reply Steve,

Please feel free to let me know if you meet any further problem.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,
I think what you mentioned should be "Control.UniqueID" :)

sorry for my posting, I wasn't reading carefully enough and assumed a
client-side thing (i.e. some JavaScript looking for the control). :-P

Cheers,
Olaf
 
Back
Top