Request.Form problem?

  • Thread starter Thread starter Fernando Lopes
  • Start date Start date
F

Fernando Lopes

Hi.
In a usercontrol (UC1) I have a textbox (txtName).
So, when i use Request.Form["txtName"], i got nothing.
But, if i use the ClientId of control, something like content$$txtName, i
got the textbox value.

What am i doing wrong?

Thanks.
Fernando
 
Nothing. If ASP.Net simply rendered the ID as the textbox name, what would
happen if you placed two of the same user control on the page? You'd end up
with two textboxes with the same name (txtName)...what behaviour would you
expect in this case (chaos! total chaos!) As such, to ensure that control
names are unique, asp.net rendered the name element as ClientId...so use
that instead....

But really, ask yourself, is it really necessary to be using Request.Form in
the first place?

Karl
 
If you have a textbox within a user control you have to expose it values as
properties. Treat the user control just like a class. So,

Public Property TextName() as String
Get
return txtName.text
End Get
Set (ByVal value as String)
me.txtName.Text = value
End Set

End Property
 
Thanks Carl.
But, if i need to check if textbox posted anything, how can i do that, not
using request.form?

Thansk again
Fernando


Karl Seguin said:
Nothing. If ASP.Net simply rendered the ID as the textbox name, what
would
happen if you placed two of the same user control on the page? You'd end
up
with two textboxes with the same name (txtName)...what behaviour would you
expect in this case (chaos! total chaos!) As such, to ensure that
control
names are unique, asp.net rendered the name element as ClientId...so use
that instead....

But really, ask yourself, is it really necessary to be using Request.Form
in
the first place?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Fernando Lopes said:
Hi.
In a usercontrol (UC1) I have a textbox (txtName).
So, when i use Request.Form["txtName"], i got nothing.
But, if i use the ClientId of control, something like content$$txtName, i
got the textbox value.

What am i doing wrong?

Thanks.
Fernando
 
dim inputtedValue as string = txtName.Text

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Fernando Lopes said:
Thanks Carl.
But, if i need to check if textbox posted anything, how can i do that, not
using request.form?

Thansk again
Fernando


Karl Seguin said:
Nothing. If ASP.Net simply rendered the ID as the textbox name, what
would
happen if you placed two of the same user control on the page? You'd end
up
with two textboxes with the same name (txtName)...what behaviour would you
expect in this case (chaos! total chaos!) As such, to ensure that
control
names are unique, asp.net rendered the name element as ClientId...so use
that instead....

But really, ask yourself, is it really necessary to be using Request.Form
in
the first place?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


Fernando Lopes said:
Hi.
In a usercontrol (UC1) I have a textbox (txtName).
So, when i use Request.Form["txtName"], i got nothing.
But, if i use the ClientId of control, something like content$$txtName, i
got the textbox value.

What am i doing wrong?

Thanks.
Fernando
 

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

Back
Top