We help IT Professionals succeed at work.
Get Started

Server error  control 'btnSubmit' of type 'Button' must be placed inside a form tag with runat=server.

augie0216
augie0216 asked
on
1,972 Views
Last Modified: 2013-12-03
I created a form in asp.net using vb.net code the form consists of a button(btnSubmit) a textbox (txthistorialprices) and and a dropdownlist (ddlStocks). When the user selects an item in the dropdownlist and clicls the submit button, thw code in the submit button should open a sequential file containing the same name as the symbol with the file suffix of .txt.. I have put three files in s shared file called C:\share.  When I run the solution I get this error: Control 'btnSubmit' of type' Button' must be placed inside a form tag with runat = server. I new at this stuff and have no idea what I did wrong. Here is all my code:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="wfmStockQuotes.aspx.vb" Inherits="Ch13Ex3.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
            <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
            <meta content="JavaScript" name="vs_defaultClientScript">
            <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">
            </form>
            <p style="FONT-WEIGHT: bold; FONT-FAMILY: Tahoma">
                  <asp:Label id="lblSymbol" style="Z-INDEX: 101; LEFT: 40px; POSITION: absolute; TOP: 56px" runat="server"
                        Width="144px">Select Symbol</asp:Label>
                  <asp:Button id="btnSubmit" style="Z-INDEX: 104; LEFT: 288px; POSITION: absolute; TOP: 248px"
                        runat="server" Text="Submit"></asp:Button>
                  <asp:TextBox id="txtHistoricalPrices" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 160px"
                        runat="server" TextMode="MultiLine" Height="136px"></asp:TextBox>
                  <asp:DropDownList id="ddlStocks" style="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 88px" runat="server">
                        <asp:ListItem Value="abc">American Co.</asp:ListItem>
                        <asp:ListItem Value="jbb">Joe Bob's</asp:ListItem>
                        <asp:ListItem Value="xan">Xtra</asp:ListItem>
                  </asp:DropDownList>Stock Quotes</p>
      </body>
</HTML>

Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblSymbol As System.Web.UI.WebControls.Label
    Protected WithEvents ddlStocks As System.Web.UI.WebControls.DropDownList
    Protected WithEvents txtHistoricalPrices As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim SR As New System.IO.StreamReader("c:\Share" & ddlStocks.SelectedValue & ".txt ")
        txtHistoricalPrices.Text = SR.ReadToEnd()
    End Sub
End Class

Thanks Augie

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 12 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE