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 July 9th, 2003, 12:28 PM
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating a form tag in code

In ASP.Net is there anyway to create a form tag (with runat=server) from within the code?

I need to create muliple groups of checkboxes but I don't know how many groups I will need or how many options are in each group.(both of these come from separate database tables)
In asp it was easy. Simplified it was this... and it would create the
the number of checkboxes I needed. And I could do this for each group.
do until RSdob.eof
 <INPUT TYPE='checkbox' value=" & RSdbo_("option") & " NAME='OptionList'>" & RSdbo("optionName")
loop

In ASP.Net I tried to do the following
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Dim item As checkboxlist
        Dim ckbArray(5) As checkboxlist

        For i = 0 To 5
            ckbArray(i) = New checkboxlist
        Next

        For i = 0 To 5
            ckbArray(i).ID = "ckbarray" & i
            ckbArray(i).Enabled = True
            ckbArray(i).Visible = True
            ckbArray(i).Text = "test"
            Controls.Add(ckbArray(i))
        Next
    End Sub

This does not produce checkboxes (it works in VB.Net and if I change
the checkboxlist to labels it works).
The error messages states that checkboxlist needs to be within a form tag with parameter runat=server.


 
Old July 10th, 2003, 12:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

in ASP.NET u can only have 1 form with RUNAT=server attribute!


Always:),
Hovik Melkomian.
 
Old July 10th, 2003, 01:44 PM
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Then is there anyway to dynamically create checkboxlists/checkboxes and radiobuttonlists/radiobuttons from code when you don't know how many of these seperate controls you will need at design time?

 
Old July 10th, 2003, 04:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

Yes.
http://msdn.microsoft.com/library/de...mmatically.asp

Regards,
NNJ

...but the Soon is eclipsed by the Moon
 
Old July 11th, 2003, 11:27 AM
Registered User
 
Join Date: Jul 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That article says controls can be create dynamically but it doesn't give an example.
In my first post in the example I gave, if the checkboxlist are changed to labels then I can dynamically create the labels but the code doesn't work with checkboxes or checkboxlists.

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Dim item As label
        Dim lblArray(5) As label

        For i = 0 To 5
            lblArray(i) = New label
            lblArray(i).ID = "ckbarray" & i
            lblArray(i).Enabled = True
            lblArray(i).Visible = True
            lblArray(i).Text = "test"
            Controls.Add(lblArray(i))
        Next
    End Sub

 
Old July 29th, 2003, 04:48 AM
Authorized User
 
Join Date: Jun 2003
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

I tried the following code and it worked for me, although it adds the checkboxes horizontally:

<%@ Page Language="VB" %>

<script runat="server">

  Sub Page_Load(sender As System.Object, e As System.EventArgs)
    Dim i, n as Integer
    Dim box as HtmlInputCheckBox

    If Page.IsPostBack Then
      i = Request.Form("num")
      For n=0 To i-1
    box = New HtmlInputCheckBox
    formDiv.Controls.Add(box)
      Next
    End If
  End Sub

</script>


<form runat="server">
  <input type="text" name="num"> Number of checkboxes <br/>
  <input type="submit">
  <div id="formDiv" runat="server" />
</form>

Cheers!
Marlon
 
Old August 1st, 2003, 06:00 PM
Authorized User
 
Join Date: Jul 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to merediths
Default


marciapz,

  I had a similar issue rendering content from a database. I simply needed more flexibility than the Web Forms framework provided. I wound up directly subclassing IHttpHandler. The folling is C# but easily portable;

  public class Class : IHttpHandler{
        ...
        ...
     private static TemplateWriter tw = new SimpleTemplateWriter();

     public void ProcessRequest(HttpContext context){
          HttpResponse res = context.Response;
          ...
          tw.startHtml(res);
          res.Write("<form>");
          res.Write("<table><tr><td>Login</td><td><input type=\"text\" name=\"txtLogin\"></td></tr>");
             res.Write("<tr><td>Password</td><td><input type=\"password\" name=\"txtPassword\"></td></tr></table>");
      res.Write("<input type=\"submit\" value=\"Login\"></form>");

          tw.stopHtml(res);
   }

    public bool IsReusable{
        get{ return true;
 ...
  ...
}

The TemplateWriter is a custom class I have that reads a file on the server containg the beginning and end of an html template; I design it in Dreamweaver and then cut and paste the code into the file. Makes for nice html, but you can ignore that part.

Regards,
Meredith Shaebanyan










Similar Threads
Thread Thread Starter Forum Replies Last Post
'FormView' must be placed inside a form tag stephena.co.uk ASP.NET 2.0 Basics 2 October 15th, 2008 08:25 AM
Creating a list depending on a tag value josephine XSLT 1 October 26th, 2007 05:39 AM
creating smart tag library Medes VS.NET 2002/2003 0 April 16th, 2006 02:56 PM
creating smart tag library Medes Visual Studio 2005 0 April 10th, 2006 03:29 PM
how to design the form by tag pages yylee Access 1 July 30th, 2005 02:23 AM





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