Request.Form problem?

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
 
K

Karl Seguin

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
 
G

Guest

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
 
F

Fernando Lopes

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
 
K

Karl Seguin

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

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top