Getting Request.Form["control"]

I am experiencing different behaviors with Request.Form.  On one set of pages, the names of the form controls rendered in the browser are beautifully the same as in the aspx source, and when the page is Server.Transferred true to a second page, that page is able to retrieve the form controls using the names I have in the first page's source.  On another web project, the names of the form controls assume the form: ctl000$FormConetnt$TextBox....

First case, aspx source:

<body onload=''>
<form id="form1" runat="server">
<div>
<h1>New Query</h1>
<p style="padding-bottom: -0.5ex;"><b>Requesting Agency</b>:</p>
Name: <asp:TextBox ID="txtboxRequestor" runat="server" Width="15em"></asp:TextBox>
&nbsp; Email: <asp:TextBox ID="txtboxEmail" runat="server" Width="12em"></asp:TextBox>
<br />

First case, browser output (I have erased some of the long view state variables and some Javascript which I think are validating scripts):

<body onload=''>
    <form name="form1" method="post" action="query.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1">
<div>

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKM... stuff deleted ... duU8Fq9Ry8Rog==" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>

    <div>
    <h1>New Query</h1>
            <p style="padding-bottom: -0.5ex;"><b>Requesting Agency</b>:</p>
            Name: <input name="txtboxRequestor" type="text"  id="txtboxRequestor" style="width:15em;" />
&nbsp; Email: <input name="txtboxEmail" type="text" id="txtboxEmail" style="width:12em;" />
            <br />

 

In the second case, and most other cases, the control names are badly disfigured.  The major difference I can think of between the two cases is that the good one did not use a MasterPage.  Is this the reason for the difference?

0
hc1
10/6/2008 2:22:07 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
678 Views

Similar Articles

[PageSpeed] 34

Hi,

The master page is the reason the controls are renamed.  It has to do this because you could get an occurance of the master page and child page having controls named the same name.

This is normal functionality.


Sincerely,
Malcolm Sheridan
Microsoft Certified Solution Developer
Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as
Answer" if a marked post does not actually answer your question.
0
malcolms
10/6/2008 2:57:13 AM

Hi hc1,

Yes, the reason is that you use the masterpage at the second case.

Becuase you use masterpage, it is inside the container control, the child control will include the name of parent control.

To known the basic principle, please refer to INamingContainer,
http://msdn.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx

Here is  articles about masterpage, please read it.

http://www.codeproject.com/KB/aspnet/masterpages.aspx
http://www.odetocode.com/articles/450.aspx

 


Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hua
10/8/2008 8:26:20 AM
Reply:

Similar Artilces:

superreview requested: [Bug 410500] Add "Web form password" description to web form keychain items : [Attachment 295140] fix
Stuart Morgan <stuart.morgan@alumni.case.edu> has asked Mark Mentovai <mark@moxienet.com> for superreview: Bug 410500: Add "Web form password" description to web form keychain items https://bugzilla.mozilla.org/show_bug.cgi?id=410500 Attachment 295140: fix https://bugzilla.mozilla.org/attachment.cgi?id=295140&action=edit ...

Multiple "Forms" in a Web Form.
Hi, this query relates to ASP.NET 2.0. I use C# but answers in C# or VB.Net is fine. I have a form to capture a person's details. The form is the usual forename, surname, etc. and the Person is held in a Person Class. What I want to be able to do is to move the form creation into a Class in a separate Class in App_Code. This will enable a button to be placed on the web form to "Add Another Person" using the class. This would create a new Person object and write a new form into the page for the second person to fill in their details. Naturally, this could continue to n Pe...

superreview requested: [Bug 390975] "ASSERTION: Form controls not ordered correctly" with form-in-table
Boris Zbarsky <bzbarsky@mit.edu> has asked Jonas Sicking <jonas@sicking.cc> for superreview: Bug 390975: "ASSERTION: Form controls not ordered correctly" with form-in-table https://bugzilla.mozilla.org/show_bug.cgi?id=390975 Attachment 275731: Proposed fix https://bugzilla.mozilla.org/attachment.cgi?id=275731&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> Maybe I should take that debug code out... it really obfuscates things. :( ...

superreview requested: [Bug 390975] [FIX]"ASSERTION: Form controls not ordered correctly" with form-in-table
Boris Zbarsky <bzbarsky@mit.edu> has asked Johnny Stenback <jst@mozilla.org> for superreview: Bug 390975: [FIX]"ASSERTION: Form controls not ordered correctly" with form-in-table https://bugzilla.mozilla.org/show_bug.cgi?id=390975 Attachment 275731: Proposed fix https://bugzilla.mozilla.org/attachment.cgi?id=275731&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> Trying different reviewer... Jonas is swamped ...

<form id="form" runat="server">
hey i have a very similar problem to this thread http://forums.asp.net/thread/1440587.aspx"Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with runat=server. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: Control 'ctl00_ContentPlaceHolder1_Login1' of type 'Login' must be placed inside a form tag with r...

When I get .XML document with Request.Form["xml"].ToString(); it gets error.
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(Request.Form["xml"].ToString());  I want system doesn't interrupt the code execution. How can I do system doesn't give error message?  Thanks.  Error Message  A potentially dangerous Request.Form value was detected from the client (xml="...8859-9" ?><BORCELIK><Tarih>09/...").  ...

Passing Data from View to Controller: Use controller parameters or Request.Form["..."]
I develop a small mvc web application (similar to dotnetkicks or kigg ;) ). I read a lot of blog posts, tutorials and saw the great videos from ScottHa.In this blogpost show us Scott how to passing data from the view to the contoller.One time he use this syntax: public void Create(string ProductName, int CategoryID...) {...}Later he recommand to use the Binding Helper - without using any method parameters. The Binding Helper is a very nice time saver, but in my opinion the "parameter"-way would be better, because everyone see, what this method "need" to work and its...

superreview granted: [Bug 307616] <input type="image"> with missing image gives "ASSERTION: Form control has a frame, but it's not a form frame" : [Attachment 207080] patch
Boris Zbarsky (out of town Dec 12 -- Jan 2) <bzbarsky@mit.edu> has granted Boris Zbarsky (out of town Dec 12 -- Jan 2) <bzbarsky@mit.edu>'s request for superreview: Bug 307616: <input type="image"> with missing image gives "ASSERTION: Form control has a frame, but it's not a form frame" https://bugzilla.mozilla.org/show_bug.cgi?id=307616 Attachment 207080: patch https://bugzilla.mozilla.org/attachment.cgi?id=207080&action=edit ------- Additional Comments from Boris Zbarsky (out of town Dec 12 -- Jan 2) <bzbarsky@mit.edu> Yep...

<authentication mode="Forms">forms name=".AUTHCOOKIE"
Hi there, I used authentication mode="Forms" with AUTHCOOKIE. my web.config looks like this <system.web> <authentication mode="Forms"><forms name=".AUTHCOOKIE" loginUrl="default.aspx" protection="All" /> </authentication><machineKey  validationKey="AutoGenerate" decryptionKey="AutoGenerate" validation="SHA1" /><authorization> <deny users="?" /> </authorization>   </system.web>    So far so good, but ... I have a f...

Sharepoint help! Error msg : "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"
hihi, I have set up a testing virtual server on my local machine. I installed win server 2003, wss 2.0, sql server 2000, and visual studio .net 2003. i tried to create a project in C# but when i build it and import the web part (.dwp) into the page, there is this error msg "A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe"  I seached most of the sites and they informed that the problem lies in the safe control in web.config i enter the safe control in web.config but i does not know where to put ...

superreview requested: [Bug 116346] Content-Type should be supplied for form data of 'enctype="multipart/ form-data"'[form sub]
Boris Zbarsky <bzbarsky@mit.edu> has asked Jonas Sicking <jonas@sicking.cc> for superreview: Bug 116346: Content-Type should be supplied for form data of 'enctype="multipart/form-data"'[form sub] https://bugzilla.mozilla.org/show_bug.cgi?id=116346 Attachment 264215: Adds Content-Type with charset to each form-data part https://bugzilla.mozilla.org/attachment.cgi?id=264215&action=edit ------- Additional Comments from Boris Zbarsky <bzbarsky@mit.edu> Looks good to me. sicking, would you sr? ...

Is "Session" the best solution for transfering variables between "Web Forms"??
Hi all; I am using an ASP.NET Web Application (with VB.NET)... and this App used to manage customers' requests.. so, ther user will handel customer#1 data for a while, then he (the user) will handle the data of customer#2. and so on.. And I need to transfer some variables value from one page (Web Form) to onother pages (Web Forms), Is the "Session" variable the BEST solution? and do you recommend me to increase its live to 60 mins or more. (In case the user need approx. 1 hour to handle customer#1 data!!)?? Example of values I want to transfer: CustomerID, RequestNo, Co...

Me.placeholder1.Page.Request.Form.Set("textbox", "test")
hi,   i need to pass some value from the masterpage to a control in the contentplaceholder, i have tryed this and i think thats the way to do it but i get an error: read-only   my code:   Me.placeholder1.Page.Request.Form.Set("textbox", "test")-ande--rap-***.net--ande.somee.com-- Request.Form is a collection of the values that were POST:ed to the page, and it's read only, since it's too late to change what was posted.Dim textbox as TextBox=TryCast(Me.placeholder1.FindControl("textbox"),TextBox)If Not textbox is Nothing Then &...

superreview requested: [Bug 116346] Content-Type should be supplied for form data of 'enctype="multipart/ form-data"'[form sub] #2
Boris Zbarsky <bzbarsky@mit.edu> has asked Johnny Stenback <jst@mozilla.org> for superreview: Bug 116346: Content-Type should be supplied for form data of 'enctype="multipart/form-data"'[form sub] https://bugzilla.mozilla.org/show_bug.cgi?id=116346 Attachment 275968: Like so https://bugzilla.mozilla.org/attachment.cgi?id=275968&action=edit ...

Web resources about - Getting Request.Form["control"] - asp.net.web-forms

Resources last updated: 12/19/2015 4:12:09 AM