Link to home
Start Free TrialLog in
Avatar of dprasad
dprasad

asked on

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>

Avatar of laotzi2000
laotzi2000

I think you missed an <html> before <form>
Avatar of dprasad

ASKER

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
<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>
ASKER CERTIFIED SOLUTION
Avatar of laotzi2000
laotzi2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial