By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,902 Members | 1,352 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,902 IT Pros & Developers. It's quick & easy.

Setting hidden input control programmatically

P: n/a
Hi all,

I have a loop in my code which builds the controls on the page.

I at one stage need to add some hidden input controls dynamically, I have
achieved this, and I have set their properties, however, there seems to be
one that I cannot set - ie, Name..

My code looks like this:

' loop starts here

' set hidden control properties
hidDataItem.Attributes("name") = intLoop
hidDataItem.Attributes("id") =
m_params.GetParameterByIndex(intLoop).m_objectName
hidDataItem.Attributes("value") =
m_params.GetParameterByIndex(intLoop).m_queryStrin gData
panelForm.Controls.Add(hidDataItem)

' loop ends here

The results look like this:

<input name="_ctl1" type="hidden" id="hidRID" value="B6xky" /><input
name="_ctl10" type="hidden" id="hidHospital" value="BRI" />

Whilst the ID and Value properties are the only ones I'll be interested in
later, ie, when the form is submitted, its making me wonder why it is that I
am unable to set the name property.

I've tried having

"name" = m_params.GetParameterByIndex(intLoop).m_objectName

when it didnt work I thought - hmm, maybe it doesn't like having an ID and a
Name that are equal (odd I know - as it'll only render HTML) but I changed
it anyway....so currently set to intLoop...

Its almost as if the 'name' property is written before you get to set
anything and thus defaults to _ctl1, _ctl2 and so on..

Any info on this one would be appreciated, as I say I can still get the form
to do what I need it to do - so no real biggy - I'd just like to understand
'why' it doesn't let me set its value.

Thanks in advance.

Regards

Rob
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
its much simpler to use RegisterHiddenField for this purpose.

anyway your problem is that you are setting the attributes instead of the
control property Id. To implement postback, the control makes the name
attribute match its ID (serverside), so you can not override the name. you
can override the id attribute, because it is not posted back, and has no
effect on server processing.
-- bruce (sqlwork.com)
"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Hi all,

I have a loop in my code which builds the controls on the page.

I at one stage need to add some hidden input controls dynamically, I have
achieved this, and I have set their properties, however, there seems to be
one that I cannot set - ie, Name..

My code looks like this:

' loop starts here

' set hidden control properties
hidDataItem.Attributes("name") = intLoop
hidDataItem.Attributes("id") =
m_params.GetParameterByIndex(intLoop).m_objectName
hidDataItem.Attributes("value") =
m_params.GetParameterByIndex(intLoop).m_queryStrin gData
panelForm.Controls.Add(hidDataItem)

' loop ends here

The results look like this:

<input name="_ctl1" type="hidden" id="hidRID" value="B6xky" /><input
name="_ctl10" type="hidden" id="hidHospital" value="BRI" />

Whilst the ID and Value properties are the only ones I'll be interested in
later, ie, when the form is submitted, its making me wonder why it is that I am unable to set the name property.

I've tried having

"name" = m_params.GetParameterByIndex(intLoop).m_objectName

when it didnt work I thought - hmm, maybe it doesn't like having an ID and a Name that are equal (odd I know - as it'll only render HTML) but I changed
it anyway....so currently set to intLoop...

Its almost as if the 'name' property is written before you get to set
anything and thus defaults to _ctl1, _ctl2 and so on..

Any info on this one would be appreciated, as I say I can still get the form to do what I need it to do - so no real biggy - I'd just like to understand 'why' it doesn't let me set its value.

Thanks in advance.

Regards

Rob

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.