Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 June 18th, 2007, 04:54 PM
Registered User
 
Join Date: May 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Controls at runtime

Hi all,
I am trying to create a whole page on the fly, it has heps of controls (radio, combo, text, dropdown, etc). Its like a survey form. I am then generating a submit button on the fly. Now the problem is that I want to add a button_click event for this button, but not sure how to? Also I would like to add other events for controls on the page (like if radio selected then unhide a couple of other controls), but again not sure how to do that at runtime.

I also tried creating a button in the design view (instead of runtime) and this works fine as then I can add click event easily, BUT problem with that is that I cannot get it to move down the page when other controls are being added at the runtime, so it basically stays where it was dragged to on the design window, and hence it overlaps with the controls created at run time.

This is my first asp.net application (framework 1.1), I would also like some advice on how to post the answers back to the database, when the form is submitted each answer would be stored in a separate row in the database, does that mean I have to call the stored procedure that many times (30-40 questions for each page) to submit each page?? Or is there a way I can pack all the answers in may be a recordset and then just send it to the database in one go??

Hope I have explained myself, please let me know if any further explanation is required.
Thanks a lot!

Regards
Ash
 
Old June 18th, 2007, 05:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This will do:

Button btn = new Button();
btn.Click += new EventHandler(btn_Click);

The btn_Click handler has to have this signature: object sender, System.EventArgs e

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old June 18th, 2007, 05:08 PM
Registered User
 
Join Date: May 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there,
Thanks for such a prompt reply.
The code you posted is in C# and I am using VB.NET. C# code is all I could find on Google, any help on how to do it in VB.NET?? And where exactly to put the code please?
Thanks!
 
Old July 2nd, 2007, 09:14 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Put the code in where you generate the instance of each control as indicated by Doug's sample.

The VB equivalent should be something like this (haven't used VB in a while):

AddHandler btn.Click, AddressOf btn_Click

This wires the handler to the event. You have to be sure this is done when you construct the controls during a postback as this is when you actually want the event to be fired.

-Peter
 
Old July 11th, 2007, 05:23 AM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ONE CRITICAL rule :


you must create the control in Page_Load event otherwise your event will not be fired.

ABhattacharyya





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Controls At Runtime with MFC. burtlo Visual C++ 2005 2 October 13th, 2007 06:36 AM
Add Runtime Controls dpkbahuguna Beginning VB 6 2 December 7th, 2006 08:55 AM
Runtime Problems after adding new controls colmtheirishman General .NET 0 January 12th, 2005 12:08 PM
Create Controls at Runtime everthalia Classic ASP Databases 2 July 30th, 2004 10:21 PM
How to create controls at runtime ? kishore_peddi C# 1 November 3rd, 2003 09:22 PM





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