F
Flemming Jensen
The idea behind this code is to standardize all my webpages in an
application to look the same by inheriting the pages from a userdefined
class. But it gives me problems regarding sessionstate...
Try creating a new asp.net web application in Visual Studio .NET 2003 on
Framework 1.1 using VB language
Call the project testform
add a new webform called "atest.aspx"
insert this code into atest.aspx:
--------------------------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="atest.aspx.vb"
Inherits="testform.atest"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>atest</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P><aspropDownList id="DropDownList1"
runat="server"></aspropDownList></P>
<P><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
<P><asp:Button id="Send" runat="server" Text="Button"></asp:Button></P>
</form>
</body>
</HTML>
--------------------------------
and insert this code into atest.aspx.vb
--------------------------------
Public Class atest
Inherits System.Web.UI.Page
'Inherits MyPage
Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Send As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Else
With DropDownList1
.Items.Add("Item1")
.Items.Add("Item2")
.Items.Add("Item3")
.Items.Add("Item4")
End With
End If
End Sub
End Class
Public Class MyPage
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim theform As Control = Page.FindControl("Form1")
Dim cntrl As Label = New Label : cntrl.Text = "My header<hr>"
theform.Controls.AddAt(0, cntrl)
cntrl = New Label : cntrl.Text = "<hr>My footer"
theform.Controls.AddAt(theform.Controls.Count, cntrl)
End Sub
End Class
--------------------------------
compile and run it.
Try selecting item number 3 and put some text into the textbox - click send.
OK - the page reloads and keeps the sessionstate (item3 is still selected
and the textbox is unchanged)
Then try moving the ' in line 3 of atest.aspx.vb so the two lines says:
'Inherits System.Web.UI.Page
Inherits MyPage
Compile and run it and do the above test again...
Now the dropdown loses its sessionstate but the textbox seems to survive!!
What am I doing wrong!!
application to look the same by inheriting the pages from a userdefined
class. But it gives me problems regarding sessionstate...
Try creating a new asp.net web application in Visual Studio .NET 2003 on
Framework 1.1 using VB language
Call the project testform
add a new webform called "atest.aspx"
insert this code into atest.aspx:
--------------------------------
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="atest.aspx.vb"
Inherits="testform.atest"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>atest</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P><aspropDownList id="DropDownList1"
runat="server"></aspropDownList></P>
<P><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></P>
<P><asp:Button id="Send" runat="server" Text="Button"></asp:Button></P>
</form>
</body>
</HTML>
--------------------------------
and insert this code into atest.aspx.vb
--------------------------------
Public Class atest
Inherits System.Web.UI.Page
'Inherits MyPage
Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents Send As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If IsPostBack Then
Else
With DropDownList1
.Items.Add("Item1")
.Items.Add("Item2")
.Items.Add("Item3")
.Items.Add("Item4")
End With
End If
End Sub
End Class
Public Class MyPage
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim theform As Control = Page.FindControl("Form1")
Dim cntrl As Label = New Label : cntrl.Text = "My header<hr>"
theform.Controls.AddAt(0, cntrl)
cntrl = New Label : cntrl.Text = "<hr>My footer"
theform.Controls.AddAt(theform.Controls.Count, cntrl)
End Sub
End Class
--------------------------------
compile and run it.
Try selecting item number 3 and put some text into the textbox - click send.
OK - the page reloads and keeps the sessionstate (item3 is still selected
and the textbox is unchanged)
Then try moving the ' in line 3 of atest.aspx.vb so the two lines says:
'Inherits System.Web.UI.Page
Inherits MyPage
Compile and run it and do the above test again...
Now the dropdown loses its sessionstate but the textbox seems to survive!!
What am I doing wrong!!