Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1490
  • Last Modified:

Control 'btn' of type 'Button' must be placed inside a form tag with runat=server.

I should be to make a selection from a group of radio buttons or a dropdownlist, make a submission that stores it as a session variable and writes it to the screen. All I get is the submit button and no choices?

I get the <form runat=server> tag underlined by VS, it says 'per the active schema, the element form must be included in a parent element'

<%@ Page Language="vb" strict="true"%>
<script runat=server>

sub btn_click(ByVal Sender as Object, ByVal e as EventArgs)

if (rbl.SelectedIndex = -1) then
lblMsg.Text = "you must select a book category."
else
dim sb as stringBuilder = new StringBuilder( )
sb.Append("you have selected")
sb.Append(Cstr(Session("cattext")))
sb.Append(" with code ")
sb.Append(Cstr(Session("catcode")))
sb.Append(""".")

lblMsg.Text = sb.ToString( )
ddl.Visible = true
dim CatBooks() as string = CType(Session("books"), string())

'populate the dropdown list

dim i as integer
ddl.Items.Clear()
      for i = 0 to CatBooks.GetLength(0) - 1
            ddl.Items.Add(new ListItem(CatBooks(i)))
      next
end if
end sub

sub rbl_SelectedIndexChanged(ByVal Sender as Object, ByVal e as EventArgs)

  if (rbl.SelectedIndex <> -1) then
  dim Books(3) as string
 
  Session("cattext") = rbl.SelectedItem.Text
  Session("catcode") = rbl.SelectedItem.Value
 
  select case (rbl.SelectedItem.Value)
 
 
  case "n"
      Books(0) = "Programming c#"
      Books(1) = "asp.net"
      Books(2) = "c3 essentials"
      
      
      
      case "d"
      Books(0) = "oracle and open"
      Books(1) = "sql"
      Books(2) = "twsl"
      

      
      case "h":
      
      Books(0) = "pc hardware in a nutshell"
      Books(1) = "dictionary of PC"
      Books(2) = "linux"
      
end select
      
      
      
      Session("books") = Books
      end if
      end sub
      
</script>

<form runat=server>
<asp:radioButtonList id="rbl" autopostback="false" cellspacing="20" repeatcolumns="3" repeatDirection="horizontal" repeatlayout="table" textalign="right" onSelectedIndexChanged="rbl_SelectedIndexChanged" runat="server"></asp:radioButtonList>

<asp:button id="btn" text="submit" onClick="btn_Click" runat="server"/>

<asp:label id="lblMsg" runat="server"/>

<asp:DropDownList id="ddl" autoPostBack="false" visible="false" runat="server"/>

</body>
</form>
</html>

0
dprasad
Asked:
dprasad
  • 3
1 Solution
 
laotzi2000Commented:
I think you missed an <html> before <form>
0
 
dprasadAuthor Commented:
ok so i have

</script>
<html>
<form runat=server>
...

VS gives me a tooltip notice over <from runat:

 '<form>' cant be nested  within 'html'

I still only see a submit button
0
 
laotzi2000Commented:
<html>
<body>
<form runat=server ID="Form1">
<asp:radioButtonList id="rbl" autopostback="false" cellspacing="20" repeatcolumns="3" repeatDirection="horizontal" repeatlayout="table" textalign="right" onSelectedIndexChanged="rbl_SelectedIndexChanged" runat="server"></asp:radioButtonList>

<asp:button id="btn" text="submit" onClick="btn_Click" runat="server"/>

<asp:label id="lblMsg" runat="server"/>

<asp:DropDownList id="ddl" autoPostBack="false" visible="false" runat="server"/>

</form>
</body>
</html>
0
 
laotzi2000Commented:
that's because your radio button list is empty:

try this:
      <body>
            <form runat="server" ID="Form1">
                  <asp:radioButtonList id="rbl" autopostback="false" cellspacing="20" repeatcolumns="3" repeatDirection="horizontal"
                        repeatlayout="table" textalign="right" onSelectedIndexChanged="rbl_SelectedIndexChanged" runat="server">
                        <asp:ListItem Value="One">One</asp:ListItem>
                        <asp:ListItem Value="Two">Two</asp:ListItem>
                        <asp:ListItem Value="Three">Three</asp:ListItem>
                  </asp:radioButtonList>
                  <asp:button id="btn" text="submit" onClick="btn_Click" runat="server" />
                  <asp:label id="lblMsg" runat="server" />
                  <asp:DropDownList id="ddl" autoPostBack="false" visible="false" runat="server" />
            </form>
      </body>
</HTML>
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now