Problemer med inherits af class
Hej Eksperter!Jeg er (igen) begyndt at lære lidt asp.net og denne gang bruger jeg ikke webmatrix men vs.net - hvilket giver mig nogle lidt specielle problemer. I webmatrix blev koden skrevet i <script>-blokke, i vs.net bruges klasser og derefter linkes med codebehind="" og formen arver fra min klasse, den giver bare en fejl:
Parser Error Message: Could not load type 'WebApplication1.WebForm1'.
Source Error:
Line 1: <%@ import Namespace="system.data" %>
Line 2: <%@ import Namespace="system.data.oledb" %>
Line 3: <%@ Page Language="vb" autoeventwireup="false" codebehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
Line 4: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 5: <HTML>
Koden til webform1.aspx:
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.oledb" %>
<%@ Page Language="vb" autoeventwireup="false" codebehind="WebForm1.aspx.vb" Inherits="WebApplication1.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">
<link href="style.css" type="text/css" rel="stylesheet">
</HEAD>
<body ms_positioning="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 56px" runat="server"
height="21px" width="144px">*nsket
brugernavn<sup>1</sup></asp:Label>
<asp:checkbox id="showtlf" style="Z-INDEX: 130; LEFT: 200px; POSITION: absolute; TOP: 472px" runat="server"
Width="104px" Height="24px"></asp:checkbox>
<asp:textbox id="beskrivelse" style="Z-INDEX: 128; LEFT: 200px; POSITION: absolute; TOP: 496px"
runat="server" Width="160px" Height="76px" Columns="20" Rows="4" TextMode="MultiLine"></asp:textbox>
<asp:textbox id="tlf" style="Z-INDEX: 127; LEFT: 200px; POSITION: absolute; TOP: 440px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="skype" style="Z-INDEX: 126; LEFT: 200px; POSITION: absolute; TOP: 408px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="msn" style="Z-INDEX: 125; LEFT: 200px; POSITION: absolute; TOP: 376px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="post" style="Z-INDEX: 124; LEFT: 200px; POSITION: absolute; TOP: 248px" runat="server"
Width="48px" MaxLength="4"></asp:textbox>
<asp:textbox id="city" style="Z-INDEX: 123; LEFT: 200px; POSITION: absolute; TOP: 216px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="mail" style="Z-INDEX: 122; LEFT: 200px; POSITION: absolute; TOP: 184px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="name" style="Z-INDEX: 121; LEFT: 200px; POSITION: absolute; TOP: 152px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="pass2" style="Z-INDEX: 120; LEFT: 200px; POSITION: absolute; TOP: 120px" runat="server"
Width="144px"></asp:textbox>
<asp:textbox id="pass" style="Z-INDEX: 119; LEFT: 200px; POSITION: absolute; TOP: 88px" runat="server"
Width="144px"></asp:textbox>
<asp:Label id="Label15" style="Z-INDEX: 115; LEFT: 48px; POSITION: absolute; TOP: 88px" runat="server"
height="21px" width="136px">*nsket
kodeord<sup>2</sup></asp:Label><asp:Label id="Label14" style="Z-INDEX: 114; LEFT: 48px; POSITION: absolute; TOP: 120px" runat="server"
height="21px" width="128px">*Gentag
kodeord<sup>2</sup></asp:Label><asp:Label id="Label13" style="Z-INDEX: 113; LEFT: 48px; POSITION: absolute; TOP: 184px" runat="server"
height="21px" width="128px">*Email-adresse<sup>3</sup></asp:Label><asp:Label id="Label12" style="Z-INDEX: 112; LEFT: 48px; POSITION: absolute; TOP: 152px" runat="server"
height="21px" width="128px">*Rigtige
navn</asp:Label><asp:Label id="Label11" style="Z-INDEX: 111; LEFT: 48px; POSITION: absolute; TOP: 216px" runat="server"
height="21px" width="128px">*By</asp:Label><asp:Label id="Label10" style="Z-INDEX: 110; LEFT: 48px; POSITION: absolute; TOP: 248px" runat="server"
height="21px" width="128px">*Postnummer</asp:Label><asp:Label id="Label9" style="Z-INDEX: 109; LEFT: 48px; POSITION: absolute; TOP: 280px" runat="server"
height="21px" width="128px">Tilmeld
nyhedsbrev</asp:Label><asp:Label id="Label8" style="Z-INDEX: 108; LEFT: 48px; POSITION: absolute; TOP: 312px" runat="server"
height="21px" width="128px">*Skole/rgang<sup>4</sup></asp:Label><asp:Label id="Label7" style="Z-INDEX: 107; LEFT: 48px; POSITION: absolute; TOP: 344px" runat="server"
height="21px" width="136px">
<strong>Frivillige oplysinger</strong></asp:Label><asp:Label id="Label6" style="Z-INDEX: 106; LEFT: 48px; POSITION: absolute; TOP: 376px" runat="server"
height="16px" width="128px">Msn</asp:Label><asp:Label id="Label5" style="Z-INDEX: 105; LEFT: 48px; POSITION: absolute; TOP: 408px" runat="server"
height="21px" width="128px">Skype</asp:Label><asp:Label id="Label4" style="Z-INDEX: 104; LEFT: 48px; POSITION: absolute; TOP: 440px" runat="server"
height="21px" width="128px">Tlf.</asp:Label><asp:Label id="Label3" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 472px" runat="server"
height="21px" width="128px">Vis
Tlf.<sup>5</sup></asp:Label><asp:Label id="Label2" style="Z-INDEX: 102; LEFT: 48px; POSITION: absolute; TOP: 504px" runat="server"
height="21px" width="128px">Beskrivelse</asp:Label>
<asp:Label id="Label16" style="Z-INDEX: 116; LEFT: 56px; POSITION: absolute; TOP: 630px" runat="server"
height="128px" width="561px"><sup>1</sup>Brugernavnet
skal vre mindst 4 tegn langt og m ikke indeholde '<br />
<sup>2</sup>Det valgte kodeord skal vre mellem 6 og 12 tegn langt.<br />
<sup>3</sup>Srg for at emailadressen er din egen da aktiveringskoden bliver sendt
til den emailadresse du angiver<br />
<sup>4</sup>rgangen skal vre det r hvor du bliver student<br />
<sup>5</sup>Telefonnummeret vil kun vre synligt for de brugere der er oprettet i samme
klasse, alts dine nuvrende/tidligere klassekammerater. </asp:Label><asp:Label id="Label17" style="Z-INDEX: 117; LEFT: 192px; POSITION: absolute; TOP: 8px" runat="server"
height="40px" width="336px" font-size="Large" font-bold="True">Opret
en bruger p besoffen.dk</asp:Label>
<asp:textbox id="bruger" style="Z-INDEX: 118; LEFT: 200px; POSITION: absolute; TOP: 56px" runat="server"
Width="144px"></asp:textbox>
<asp:checkbox id="nyhedsbrev" style="Z-INDEX: 129; LEFT: 200px; POSITION: absolute; TOP: 280px"
runat="server" Width="104px" Height="24px" Checked="True"></asp:checkbox>
<asp:dropdownlist id="DropDownList1" style="Z-INDEX: 131; LEFT: 200px; POSITION: absolute; TOP: 312px" runat="server" DataSource="<%# Page %>" Width="128px" Height="24px" AutoPostBack="True" Runat="server">
</asp:dropdownlist>
<asp:button id="Button1" style="Z-INDEX: 132; LEFT: 240px; POSITION: absolute; TOP: 584px" runat="server"
Width="56px" Text="Opret!"></asp:button>
</form>
</body>
</HTML>
og koden til webform1.aspx.vb:
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 Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents Label9 As System.Web.UI.WebControls.Label
Protected WithEvents Label10 As System.Web.UI.WebControls.Label
Protected WithEvents Label11 As System.Web.UI.WebControls.Label
Protected WithEvents Label12 As System.Web.UI.WebControls.Label
Protected WithEvents Label13 As System.Web.UI.WebControls.Label
Protected WithEvents Label14 As System.Web.UI.WebControls.Label
Protected WithEvents Label15 As System.Web.UI.WebControls.Label
Protected WithEvents Label17 As System.Web.UI.WebControls.Label
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
Protected WithEvents Label16 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents showtlf As System.Web.UI.WebControls.CheckBox
Protected WithEvents beskrivelse As System.Web.UI.WebControls.TextBox
Protected WithEvents tlf As System.Web.UI.WebControls.TextBox
Protected WithEvents skype As System.Web.UI.WebControls.TextBox
Protected WithEvents msn As System.Web.UI.WebControls.TextBox
Protected WithEvents post As System.Web.UI.WebControls.TextBox
Protected WithEvents city As System.Web.UI.WebControls.TextBox
Protected WithEvents mail As System.Web.UI.WebControls.TextBox
Protected WithEvents name As System.Web.UI.WebControls.TextBox
Protected WithEvents pass2 As System.Web.UI.WebControls.TextBox
Protected WithEvents pass As System.Web.UI.WebControls.TextBox
Protected WithEvents bruger As System.Web.UI.WebControls.TextBox
Protected WithEvents nyhedsbrev As System.Web.UI.WebControls.CheckBox
'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
Dim conn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("besoffen.mdb"))
Dim aAdapter As System.Data.OleDb.OleDbDataAdapter
Dim sql As String
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
'Hiv data ud til DropDownList1 med skoler
If Not Page.IsPostBack Then
sql = "select id, skolenavn from skoler order by skolenavn"
conn.Open()
aAdapter = New System.Data.OleDb.OleDbDataAdapter(sql, conn)
'Dim dsSkoler As System.Data.DataSet = New System.Data.DataSet
'aAdapter.Fill(dsSkoler, "skoler")
DropDownList1.DataSource = aAdapter
DropDownList1.DataTextField = "Skolenavn"
DropDownList1.DataValueField = "ID"
DropDownList1.DataBind()
conn.Close()
End If
End Sub
Sub DropDownList1_Change(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
'Hiv data ud til DropDownList2 med klasser p valgte skole
'DropDownList1.selecteditem.value til at hente id for skolen
sql = "select klasse, id from klasser where SkoleID=" & DropDownList1.SelectedItem.Value & " order by klasse"
conn.Open()
aAdapter = New System.Data.OleDb.OleDbDataAdapter(sql, conn)
'Dim dsKlasser As System.Data.DataSet = New System.Data.DataSet
'aAdapter.Fill(dsKlasser, "klasser")
DropDownList2.DataSource = aAdapter
DropDownList2.DataTextField = "klasse"
DropDownList2.DataValueField = "id"
DropDownList2.DataBind()
conn.Close()
End Sub
End Class
Endvidere kunne jeg godt tænke mig at min databinding kommer til at virke(hvis der er nogle fejl), ideen er at dropdownlist med klasser kun vises når en skole er valgt, og det er de klasser der findes på den pågældende skole der skal vises.
På forhånd tak
Casper Schmidt