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

Discussion in 'ASP .Net' started by Flemming Jensen, Aug 22, 2003.

  1. 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><asp:DropDownList id="DropDownList1"
    runat="server"></asp:DropDownList></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!!
     
    Flemming Jensen, Aug 22, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. titof
    Replies:
    0
    Views:
    584
    titof
    Jul 24, 2003
  2. timmso
    Replies:
    1
    Views:
    580
    Alex Papadimoulis
    Dec 12, 2003
  3. =?Utf-8?B?bXN1aw==?=

    Using one webform to set a value on another webform

    =?Utf-8?B?bXN1aw==?=, Jul 12, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    531
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Jul 12, 2006
  4. =?Utf-8?B?Vk1J?=

    Moving value from popup Webform to main Webform?

    =?Utf-8?B?Vk1J?=, Oct 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    626
    GroupReader
    Oct 9, 2006
  5. Luqman
    Replies:
    2
    Views:
    706
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 11, 2007
Loading...

Share This Page