I need to dynamically add an html control to a web form.
What I have, thus far, adds the control to the page, but only places it
after the closing "</html>" tag.
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden();
h.ID = "FIELD1";
h.Value = "Value1";
Page.Controls.Add (h);
Is there a way to have the control added inside the "<form>" tags?
Thanks,
Scott Natwick 6 2232
I found an example that may help, but I haven't been able to get it to work.
The example suggests obtaining a reference to the Form, then adding the
control the From.
Page.FindControl("form1").Controls.Add(btnDyn)
<form id="form1" runat="server">
</form>
I tried this, but I receive an error when trying to access the Form.
"System.NullReferenceException: Object reference not set to an instance of
an object." http://authors.aspalliance.com/wisem...px?id=AN021002
"Test Message" <te*********@yahoo.com> wrote in message
news:iO********************@comcast.com... I need to dynamically add an html control to a web form.
What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag.
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FIELD1"; h.Value = "Value1"; Page.Controls.Add (h);
Is there a way to have the control added inside the "<form>" tags?
Thanks, Scott Natwick
Test Message wrote: I need to dynamically add an html control to a web form.
What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag.
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FIELD1"; h.Value = "Value1"; Page.Controls.Add (h);
Is there a way to have the control added inside the "<form>" tags?
Thanks, Scott Natwick
Just change the form tag into an HTML Control (by adding
runat="server" and id="form1".
Then use form1.Controls.Add(h) instead of Page.Controls.Add(h)
--
Jos
Thanks Jos for the reply!
I did try what you suggested, however I'm still having difficulty on two
counts.
First, I'm not able to add the "runat="server"". When I do, the form button
Submit does not seem function. I have an "action="http..."" in the form tag
as I need the form to submit data to another site. When I add the
runat="server" to the form tag, the Submit button does not trigger a trasfer
to the other page.
Second, I wasn't able to successfully reference the "form1" in the code. I
just receive a compile error.
Does this make sense?
Thanks again.
Scott Natwick
"Jos" <jn*************@fastmail.fm> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Test Message wrote: I need to dynamically add an html control to a web form.
What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag.
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FIELD1"; h.Value = "Value1"; Page.Controls.Add (h);
Is there a way to have the control added inside the "<form>" tags?
Thanks, Scott Natwick
Just change the form tag into an HTML Control (by adding runat="server" and id="form1".
Then use form1.Controls.Add(h) instead of Page.Controls.Add(h)
--
Jos
Thanks for your help. This might be a hack, but I think I found something
that works.
I added a label to the form, then added the new control to the label.
<asp:Label id="Label1" runat="server"></asp:Label>
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden();
h.ID = "FieldId";
h.Value = "Value";
Label1.Controls.Add (h);
Scott Natwick
"Scott Natwick" <no**********@yahoo.com> wrote in message
news:WO********************@comcast.com... Thanks Jos for the reply!
I did try what you suggested, however I'm still having difficulty on two counts.
First, I'm not able to add the "runat="server"". When I do, the form button Submit does not seem function. I have an "action="http..."" in the form tag as I need the form to submit data to another site. When I add the runat="server" to the form tag, the Submit button does not trigger a trasfer to the other page.
Second, I wasn't able to successfully reference the "form1" in the code. I just receive a compile error.
Does this make sense?
Thanks again. Scott Natwick
"Jos" <jn*************@fastmail.fm> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Test Message wrote: I need to dynamically add an html control to a web form.
What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag.
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FIELD1"; h.Value = "Value1"; Page.Controls.Add (h);
Is there a way to have the control added inside the "<form>" tags?
Thanks, Scott Natwick
Just change the form tag into an HTML Control (by adding runat="server" and id="form1".
Then use form1.Controls.Add(h) instead of Page.Controls.Add(h)
--
Jos
If I remember correctly, using the <asp:Label> control will render a <span>
tag to the client. If you don't want to render any html to the client and
still designate a certain place in the web you would like to dynamically add
controls to then I would use the <asp:PlaceHolder> control instead of the
<asp:Label> control.
-Chris
~ http://weblogs.austinspad.com/caustin
"Scott Natwick" <no**********@yahoo.com> wrote in message
news:rP********************@comcast.com... Thanks for your help. This might be a hack, but I think I found something that works.
I added a label to the form, then added the new control to the label.
<asp:Label id="Label1" runat="server"></asp:Label>
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FieldId"; h.Value = "Value"; Label1.Controls.Add (h);
Scott Natwick
"Scott Natwick" <no**********@yahoo.com> wrote in message news:WO********************@comcast.com... Thanks Jos for the reply!
I did try what you suggested, however I'm still having difficulty on two counts.
First, I'm not able to add the "runat="server"". When I do, the form button Submit does not seem function. I have an "action="http..."" in the form tag as I need the form to submit data to another site. When I add the runat="server" to the form tag, the Submit button does not trigger a trasfer to the other page.
Second, I wasn't able to successfully reference the "form1" in the code. I just receive a compile error.
Does this make sense?
Thanks again. Scott Natwick
"Jos" <jn*************@fastmail.fm> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Test Message wrote: I need to dynamically add an html control to a web form.
What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag.
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FIELD1"; h.Value = "Value1"; Page.Controls.Add (h);
Is there a way to have the control added inside the "<form>" tags?
Thanks, Scott Natwick
Just change the form tag into an HTML Control (by adding runat="server" and id="form1".
Then use form1.Controls.Add(h) instead of Page.Controls.Add(h)
--
Jos
Chris,
Thank you for your suggestion -- it was a good one!.
Using the Label tag did create a <span> tag and changing to the PlaceHolder
did not.
Scott
"Chris Austin" <ca*****@austinspad.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... If I remember correctly, using the <asp:Label> control will render a <span> tag to the client. If you don't want to render any html to the client and still designate a certain place in the web you would like to dynamically add controls to then I would use the <asp:PlaceHolder> control instead of the <asp:Label> control.
-Chris ~ http://weblogs.austinspad.com/caustin
"Scott Natwick" <no**********@yahoo.com> wrote in message news:rP********************@comcast.com... Thanks for your help. This might be a hack, but I think I found something that works.
I added a label to the form, then added the new control to the label.
<asp:Label id="Label1" runat="server"></asp:Label>
System.Web.UI.HtmlControls.HtmlInputHidden h = new HtmlInputHidden(); h.ID = "FieldId"; h.Value = "Value"; Label1.Controls.Add (h);
Scott Natwick
"Scott Natwick" <no**********@yahoo.com> wrote in message news:WO********************@comcast.com... Thanks Jos for the reply!
I did try what you suggested, however I'm still having difficulty on two counts.
First, I'm not able to add the "runat="server"". When I do, the form button Submit does not seem function. I have an "action="http..."" in the form tag as I need the form to submit data to another site. When I add the runat="server" to the form tag, the Submit button does not trigger a trasfer to the other page.
Second, I wasn't able to successfully reference the "form1" in the code. I just receive a compile error.
Does this make sense?
Thanks again. Scott Natwick
"Jos" <jn*************@fastmail.fm> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... Test Message wrote: > I need to dynamically add an html control to a web form. > > What I have, thus far, adds the control to the page, but only places > it after the closing "</html>" tag. > > System.Web.UI.HtmlControls.HtmlInputHidden h = new > HtmlInputHidden(); h.ID = "FIELD1"; > h.Value = "Value1"; > Page.Controls.Add (h); > > Is there a way to have the control added inside the "<form>" tags? > > Thanks, > Scott Natwick
Just change the form tag into an HTML Control (by adding runat="server" and id="form1".
Then use form1.Controls.Add(h) instead of Page.Controls.Add(h)
--
Jos
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim T |
last post by:
Hi,
I have the need to use dynamically loaded user controls in a webform page.
I have the controls loading dynamically, and that part works fine. this is
the code used in a webform to dynamically...
|
by: Donald Xie |
last post by:
Hi,
I noticed an interesting effect when working with controls that are
dynamically loaded. For instance, on a web form with a PlaceHolder control
named ImageHolder, I dynamically add an image...
|
by: Kamal Jeet Singh |
last post by:
Hi Friends !!
I am have facing problem in controlling the dynamically created
controls on web page. The problem Scenario is
Scenario:- My requirement is to load the web user controls on the...
|
by: Kamal Jeet Singh |
last post by:
Hi Friends !!
I am facing problem in controlling the dynamically created
controls on web page. The problem Scenario is
Scenario:- My requirement is to load the web user controls on the web...
|
by: Chad |
last post by:
I have a problem that I am desperate to understand.
It involves dynamically adding controls to a Table control that is built as a result of performing a database query.
I am not looking to...
|
by: Reza Nabi |
last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a
placeholder dynamically based on the ctlName querystring passed in the URL.
Webform (LoadCtl.aspx) also passes a...
|
by: Steve Booth |
last post by:
I have a web form with a button and a placeholder, the button adds a user
control to the placeholder (and removes any existing controls). The user
control contains a single button. I have done all...
|
by: BillE |
last post by:
When I create a control dynamically and it grows according to the content,
the control Height property still returns the original default control
height instead of the height after expanding.
...
|
by: RichB |
last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am
trying to add a tabbed control to the page.
I have no problems within the aspx file, and can dynamically manipulate a...
|
by: Allen Chen [MSFT] |
last post by:
Hi Richard,
Quote from Richard==================================================
However I also want to be able to remove the
panes. I have tried to include this, but find that when I first...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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,...
| |