Wrox Programmer Forums
|
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
 
Old August 7th, 2006, 11:05 PM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default 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

 
Old August 8th, 2006, 12:32 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old August 8th, 2006, 04:05 AM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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

 
Old August 8th, 2006, 04:08 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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
 
Old August 8th, 2006, 11:15 PM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default

yes. We are creating entire page from scratch. Can you give me the coding.....

Regards,
Sathya M

 
Old August 9th, 2006, 01:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old August 9th, 2006, 06:55 AM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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

 
Old August 9th, 2006, 07:17 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

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.
 
Old August 9th, 2006, 11:05 PM
Authorized User
 
Join Date: Mar 2006
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thak you Imar






Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding User Forms at Run time RichRansom BOOK: Excel 2007 VBA Programmer's Reference ISBN: 978-0-470-04643-2 0 May 30th, 2008 11:49 AM
Design-Time or Run-Time now ? ALGNET .NET Framework 2.0 1 July 31st, 2006 04:43 AM
Adding Text boxes on run time jmss66 VB How-To 1 March 31st, 2006 03:32 PM
Adding new field to a database table in run time dotnet cat ASP.NET 1.0 and 1.1 Basics 1 October 6th, 2005 01:36 PM
Adding controls at run-time !! kishore_peddi C# 0 October 13th, 2003 06:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.