473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Setting hidden input control programmatically

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
1 2354
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: J Krugman | last post by:
I have a form with a couple of submit buttons, plus a "pseudolink" that is also supposed to submit the form; the submitted form data feeds to a CGI script. The two submit buttons have the name...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
3
by: Andy Fish | last post by:
Hi, I want to generate a value with javascript and include it in the form postback for a web form. based on my previous web development experience, I think I need an <input type=hidden> on...
6
by: Andre Ranieri | last post by:
I'm trying to create a login page for customers to log into our corporate website, our presidents naturally wants the user and password fields to populate from a cookie so the customer doesn't have...
14
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... ...
4
by: WB | last post by:
Hi, I need to validate a hidden input in my webform to ensure that it's got value. The controls look something like this: <input id="HidSelectedStates" type="hidden" runat="server" /><br...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
11
by: newbie | last post by:
i have a form in which a hidden field (initial value as '0', and my javascript set it to '1' when an event is trigged). In the same form, i have a reset field. But I realized that the hidden field...
2
by: corykendall | last post by:
Here is my code: ... Setting hidden input to: <dsp:valueof param="tabname"/> <input name="tabname" type="hidden" value='<dsp:valueof param="tabname"/>'/> </dsp:form> hidden input set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.