 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 7th, 2006, 11:05 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Adding button at run time
Dear All,
This is Sathya. I am working for a project .In that project i have to generate asp controls(button) in runtime. I tried with the following code.
Button btnnew = new Button();
btnnew.id="new button";
.......
this.controls.add(btnnew);
When i run the program i am getting an error stating that [b]Button Should be placed in side the <form> tag in .aspx page[/b]
I saw one solution that says drag a placeholder/literal control on form and add control to that placeholder/literal. But i was not allowed to drag and drop any controls at design time.
Need your suggestions
with Regards,
Sathya M
|
|

August 8th, 2006, 12:32 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
quote:But i was not allowed to drag and drop any controls at design time.
|
Heuh?? That's the whole idea of the design surface.
Are you sure that page was switched to Design View and your application wasn't in Debug mode anymore?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

August 8th, 2006, 04:05 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
No. We are not using Design mode. Using code behind technic we have to generate controls. Is it possible for asp button control to create from code behind logic just as in windows forms
|
|

August 8th, 2006, 04:08 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Yes, that's possible with pretty much the code you have right now.
However, as you suggested, you need to add it to a container, like a PlaceHolder.
Why can't you add a single PlaceHolder on the page directly between the <form> tags? You're not creating the entire page from scratch, are you?
Imar
|
|

August 8th, 2006, 11:15 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
yes. We are creating entire page from scratch. Can you give me the coding.....
Regards,
Sathya M
|
|

August 9th, 2006, 01:24 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
If you are creating the *entire* page from scratch, then what is your run-time environment? That is, where does the code run that creates the page from scratch? I don't think you can create the entire page from scratch at run-time...
Can you show us some of your code?
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
|
|

August 9th, 2006, 06:55 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hi Imar
My friend the previous post was posted by my friend, he did a mistake.
Actually we are not creating entire page from scratch. We are trying to place a asp button in the page at runtime ie. The code which i was given in my first post is placed in load event page.
Then after running the program we are getting "Control should be placed in side the form tag......"
With Regards,
Sathya
|
|

August 9th, 2006, 07:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
In that case, do what you or your friend suggested earlier: add a placeholder to the main form, and add the button to this placeholder.
E.g.
<asp:PlaceHolder id="plcMain" runat="server">
</asp:PlaceHolder>
Code behind:
plcMain.Controls.Add(myNewButton);
HtH,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

August 9th, 2006, 11:05 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thak you Imar
|
|
 |