Click here to Skip to main content
15,877,618 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi My proyect ASP VB.net consists in a MasterPage and WebForm.aspx

In the master page I have two controls, a textbox and a label. I needed to put them inside a tag to make them work.

In my .aspx I have more controls such as DropDownList, GridView, Buttons and some checkboxes.

Theese last ones won't work unless I put them inside a tag, but when I execute I recive "A page can have only one server-side Form tag." message.

I understand the message, so i take away the runat tag in my .aspx.

I also played a bit with Enable AutoPostBack property in the controls and also in the code.

Also I put in my .aspx behind code this VB code:

With this las code, the DropDownLists get filled with data, but when I selecet an item, the .aspx webpage seems to reload and the selection don't ocur.

Thanks for your time and help.

What I have tried:

VB
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
        'Required to verify that the control is rendered properly on page
End Sub

VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            For i = 0 To Me.Controls.Count - 1
                VerifyRenderingInServerForm(Me.Controls.Item(i))
            Next
End Sub
Posted
Updated 25-May-21 6:30am

1 solution

As the error says, a WebForms page can only contain a single (visible) server-side form.

(Technically you can have more than one, so long as only one is visible at a time.)

If you have controls in both the master page and the content page which require a server-side form, then you need to ensure that the ContentPlacholder is wrapped in the form as well.
 
Share this answer
 
Comments
DSBE 26-May-21 17:08pm    
I wrapped the MasterPage in a tag.
in the content page I also tag. and the page loads ok.
But the problem of the content page control persists.
Richard Deeming 27-May-21 3:52am    
Read my answer again - you can only have ONE <form runat="server"> visible on the page at a time.

If you have controls in the master page and in the content pages which require a server form, then you have to wrap the master page controls and the ContentPlaceholder elements in a single server form in the master page. Do not add another server form in the content page.
DSBE 27-May-21 19:07pm    
Thanks
I get a little messy with that, so I took away te text box and button from the masterpage and everything works.
One of theese days I'll try agin with this, just to learn
Thankyou very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900