locked
Form problem in http handler with dynamic control RRS feed

  • Question

  • User1970795084 posted
    Hi, I've already posted about this problem but I think I didn't explain it very well. Let me try and clarify it. I have written a cms that lets users create pages. These pages are stored in a database along with a path they want to give it. eg products/overview.aspa. The .aspa extension is enforced in the cms because all requests to .aspa files are handled by my PageHandler class. This looks up the path in the db and loads the appropriate user controls to display the page. This works well, but my problem is that I want to have a server-side form tag so I can do postbacks from some of the controls. I know form tags aren't meant to go in user controls, but I don't have an aspx page to put them in because the http handler is generating the page. I tried dynamically creating the form object in the http handler code, but I get the error "A page can have only one server-side Form tag". So I guess my question (finally!) is why does it think I have more than one form??? Is one being created automatically that I don't know about (although it isn't being output in the html)? Any help would be greatly appreciated, I've been struggling with this one for too long! Here's my code: Imports System.IO Public Class PageHandler Inherits System.Web.UI.Page Protected Overrides Sub OnInit(ByVal e As EventArgs) Dim objStreamWriter As StreamWriter = New StreamWriter(HttpContext.Current.Response.OutputStream) Dim objHtmlWriter As HtmlTextWriter = New HtmlTextWriter(objStreamWriter) Dim ctrl As PageTemplate = LoadControl(GetTemplatePath()) Dim form As New System.Web.UI.HtmlControls.HtmlForm form.ID = "form_main" Page.Controls.Add(form) form.Controls.Add(ctrl) form.RenderControl(objHtmlWriter) End Sub Private Function GetTemplatePath(ByVal intPageTemplateId As Integer) As String Return "/controls/page.ascx" End Function End Class Thanks! Rob
    Tuesday, July 27, 2004 7:42 AM

All replies

  • User1970795084 posted
    Thanks for all the help everyone (!) I figured it out in the end though.... I didn't need to call the RenderControl() method - simply adding the controls to the page is enough. That's why I was getting the duplication of form tags - seems obvious now! So for anyone who is doing something similar, the code for oninit() is now:
    Protected Overrides Sub OnInit(ByVal e As EventArgs)
            Dim ctrl As PageTemplate = LoadControl(GetTemplatePath())
            Dim form As New System.Web.UI.HtmlControls.HtmlForm
            form.ID = "form_main"
            Page.Controls.Add(form)
            form.Controls.Add(ctrl)
        End Sub
    
    
    
    
    
    
    
    
    
    
    
    
    Tuesday, August 3, 2004 9:58 AM