473,761 Members | 10,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding a HtmlInputHidden to a HtmlForm not working

In CreateChildCont rols method of my Page, I am trying to see if a hidden
input field is present (by id) and if not, add it to a predefined form (by
id).

protected override void CreateChildCont rols()
{
base.CreateChil dControls();

HtmlForm form = FindControl("my Form") as HtmlForm;

HtmlInputHidden hiddenField = form.FindContro l("hiddenId") as
HtmlInputHidden ;
if (hiddenField == null)
{
hiddenField = new HtmlInputHidden ();
hiddenField.Id = "hiddenId";
form.Controls.A dd(hiddenField) ;
}
// Controls.Add(hi ddenField);
}

Now if I uncomment the last Controls.Add line, it will add the hidden field
to the page outside of the form which is not what I want.
Can someone point me out?
Thanks.
Nov 18 '05 #1
2 4192
Hi Jiho,
Your code look right to me and it worked for me for an existing web form
and the hidden field was added
inside the form tags.So form.Controls.A dd(hiddenField) ; is working.Probabl y
some other event code is executing for the form which make it disappear when
you
go through the control execution life cycle.
Are you using Visual Studio .NET?.I tested it with Visual Studio .NET 2003.
Hope this helps.
Regards,
Marshal Antony
..NET Developer
http://www.dotnetmarshal.com

"Jiho Han" <ji******@infin ityinfo.com> wrote in message
news:ui******** ******@TK2MSFTN GP09.phx.gbl...
In CreateChildCont rols method of my Page, I am trying to see if a hidden
input field is present (by id) and if not, add it to a predefined form (by
id).

protected override void CreateChildCont rols()
{
base.CreateChil dControls();

HtmlForm form = FindControl("my Form") as HtmlForm;

HtmlInputHidden hiddenField = form.FindContro l("hiddenId") as
HtmlInputHidden ;
if (hiddenField == null)
{
hiddenField = new HtmlInputHidden ();
hiddenField.Id = "hiddenId";
form.Controls.A dd(hiddenField) ;
}
// Controls.Add(hi ddenField);
}

Now if I uncomment the last Controls.Add line, it will add the hidden field to the page outside of the form which is not what I want.
Can someone point me out?
Thanks.

Nov 18 '05 #2
After trying the same code - my code wasn't exactly as simple as the snippet
:) - separately and confirming that it does work, I still could not get it
to work.
However, a little variation of the control addition did the trick and that
is to use AddAt method.
I guess you can insert it at any position but it probably makes sense to put
it near the top or the bottom. Still adding to the end of the controls
collection did not work.
Then, I figured maybe I'll remove a couple of controls at the bottom and try
it again. That worked. I put them back and tried again. Now everything
works. Go figure.

Thanks though for looking into this. Much appreciated.
Jiho

"Marshal Antony" <do***********@ yahoo.com> wrote in message
news:el******** ******@tk2msftn gp13.phx.gbl...
Hi Jiho,
Your code look right to me and it worked for me for an existing web form and the hidden field was added
inside the form tags.So form.Controls.A dd(hiddenField) ; is working.Probabl y some other event code is executing for the form which make it disappear when you
go through the control execution life cycle.
Are you using Visual Studio .NET?.I tested it with Visual Studio .NET 2003. Hope this helps.
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com

"Jiho Han" <ji******@infin ityinfo.com> wrote in message
news:ui******** ******@TK2MSFTN GP09.phx.gbl...
In CreateChildCont rols method of my Page, I am trying to see if a hidden
input field is present (by id) and if not, add it to a predefined form (by id).

protected override void CreateChildCont rols()
{
base.CreateChil dControls();

HtmlForm form = FindControl("my Form") as HtmlForm;

HtmlInputHidden hiddenField = form.FindContro l("hiddenId") as
HtmlInputHidden ;
if (hiddenField == null)
{
hiddenField = new HtmlInputHidden ();
hiddenField.Id = "hiddenId";
form.Controls.A dd(hiddenField) ;
}
// Controls.Add(hi ddenField);
}

Now if I uncomment the last Controls.Add line, it will add the hidden

field
to the page outside of the form which is not what I want.
Can someone point me out?
Thanks.


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1881
by: Kjell Arne | last post by:
Hi, How do one add parameters to a URL from a UserControl? My problem is that I want to set a unique value to the webpage when the page loads. This value I will use as a identifier for that session (user). I'm certain it's a simple solution for this. But I have not been able to locate it yet. Usually in the old days, I would just generate input hidden tags in the
4
5482
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
0
1100
by: Julius Fenata | last post by:
Okay, I have pass new value from client to server, like this: <script language="JavaScript"> function JSGenerateArticleID() { HiddenValue.value = "test"; } </script>
14
8165
by: Laser Lu | last post by:
Hello, All, I just want to know that generally how to get the HtmlForm element in an ASP.NET Page? Can anybody help? Please:) Best regards, Laser Lu
6
436
by: Nathan Sokalski | last post by:
I am trying to dynamically add controls to my page, but am having trouble with controls such as buttons. I have been able to add simple controls such as Label controls, because they can be placed anywhere. I have managed to add Labels using the following code: Dim extralabel As Label = New Label extralabel.Text = "Generated Label" Me.Controls.Add(extralabel)
6
1461
by: heybrakywacky | last post by:
After hours of pulling my hair out on this one, I've finally realized that the problem I'm having in my code is due to behavior that is not at all expected. Using ASP.NET 1.1.4322.2032, I'm trying to update a dynamically-created hidden control on my form, across multiple postings. My experience suggests that once the initial version of the hidden control has been created and populated, there is no changing that value in subsequent...
3
5494
by: Mark Denardo | last post by:
I'm trying to dynamically create and add controls to a web page: Label obj1 = new Label(); DropDownList obj2 = new DropDownList(); Controls.Add(obj1); Controls.Add(obj2); But I get the following error when the DDL is added (but not the Label): "Control 'ctl07' of type 'DropDownList' must be placed inside a form tag
0
1633
by: Bruno | last post by:
Hello guys, I'm having problem using tagMapping with HtmlForm, I have this in web.config: <tagMapping> <add tagType="System.Web.UI.HtmlControls.HtmlForm" mappedTagType="CustomForm" /> </tagMapping> It just doesn't work... it compiles ok, but the HtmlForm is not mapped to
2
1700
by: kalaivanan | last post by:
hi, i am trying to add a datagrid control to a web page dynamically. i am able to do it while i used the following code in the page load event of the form in which i am going to add the control. DataGrid dG = new DataGrid(); Control frm = FindControl("frmSnAInformation"); frm.Controls.Add(dG); DataSet ds = nam_Db.dbFunctions.funFetchDataSet("fetchSuInfo_all"); dG.DataSource = ds.Tables;
0
9521
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9333
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9945
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8768
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5361
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.