Results 1 to 3 of 3

Thread: RenderControl and DropDownList and "must be placed inside a form tag"

  1. #1

    Thread Starter
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    Unhappy RenderControl and DropDownList and "must be placed inside a form tag"

    Hi,

    I'm getting the following error message when trying to run my aspx page....

    Control 'drddropDown1' of type 'DropDownList' must be placed inside a form tag with runat=server

    Basically, I'm trying to reponse.write a control on to the page.

    It happens on the drddropDown1.RenderControl(myHtmlTextWriter)
    code.

    I dropped a dropdownlist control into a webpage(aspx), and then I call the function below with the control as an argument. Here is the code...

    a Code:
    1. Public Function BuildAndDisplay(ByRef drddropDown1 As DropDownList)
    2.  
    3.  
    4.        'I do stuff here, where I add items to the dropdownlist control
    5.  
    6.  
    7.         Dim myTextWriter As New System.IO.StringWriter
    8.         Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter)
    9.         drddropDown1.RenderControl(myHtmlTextWriter)
    10.         HttpContext.Current.Response.Write(myTextWriter.ToString)
    11.  
    12.  
    13.     End Function

    I'm baffled. I'm not sure what I'm doing wrong. :-(
    My other concern, is if I get this to work, while I be able to get a postback on an event.

    Any help is greatly appreciated. Let me know if you need more info from me.
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  2. #2

    Thread Starter
    Addicted Member silentthread's Avatar
    Join Date
    Jun 2006
    Location
    Miami, Florida
    Posts
    143

    Re: RenderControl and DropDownList and "must be placed inside a form tag"

    I'm getting closer....

    Code:
    function ForcePostBack(control)
    {
    __doPostBack(control,'SelectedIndexChange',this.value);
    }
    vbcode Code:
    1. drddropDown1.Attributes.Add("OnChange", "ForcePostBack('drddropDown1','')")



    vbcode2 Code:
    1. Private Sub drddropDown1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drddropDown1.SelectedIndexChanged
    2.  
    3.         Response.Write("<script>alert('test');</script>")
    4.  
    5.     End Sub


    The page post back, when you change an item in the drop down list, but the only problem now is that it's not executing the code in the drddropDown1_SelectedIndexChanged Sub. It's posting back, but maybe it does not know what event to process.

    Help me if you can. :-(
    Watch media as you download it! Excellent tool!
    FREE CUBA!
    MyBlog
    If you feel my post has helped, please rate it.

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: RenderControl and DropDownList and "must be placed inside a form tag"

    You shouldn't be using response to generate asp.net controls. Let the framework do it for you with the controls collection of the page.

    http://support.microsoft.com/kb/317515

    if you need them in a certain spot, consider using a placeholder.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width