Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Who can help me with this simple webform problem?? (SessionState)

Reply
Thread Tools

Who can help me with this simple webform problem?? (SessionState)

 
 
Flemming Jensen
Guest
Posts: n/a
 
      08-22-2003
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!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Another webform without closing the current webform ? Luqman ASP .Net 2 04-11-2007 02:43 AM
Moving value from popup Webform to main Webform? =?Utf-8?B?Vk1J?= ASP .Net 1 10-09-2006 05:15 PM
Using one webform to set a value on another webform =?Utf-8?B?bXN1aw==?= ASP .Net 1 07-12-2006 07:23 PM
no code in webform using vs.net, but in webform using notepad timmso ASP .Net 1 12-12-2003 04:30 PM
Including WebForm Image Control in a Webform Table Control titof ASP .Net 0 07-24-2003 01:01 PM



Advertisments