Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Unable to transfer session data from form to form

$
0
0

User Name Input Form

I am using VS 2012 up5 & C# on Windows 7 Pro OS. I am a novice to ASP.Net and learning how to use session state for web forms. I have two simple forms that I am trying to transfer a user name from textbox input to a blank page using session state data. When I click the button event nothing happens, I don't see the next form with a user name. Here is my code snippets. What am I missing here?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FillSessionName.aspx.cs" Inherits="FillSessionName" EnableSessionState="True" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server"><div><asp:Label ID="PageText" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />&nbsp;<asp:Label ID="Label1" runat="server" Text="User Name:"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>&nbsp;&nbsp;<asp:Button ID="btnsend" runat="server" Text="Send Text Value to Next Page" /></div></form></body></html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class FillSessionName : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PageText.Text = "Page Loaded Text Here";
    }
    protected void btnsend_Click(object sender, EventArgs e)
    {
        Session["Username"] = txtUsername.Text;
        Response.Redirect("ShowSessionName.aspx");
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ShowSessionName : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Username"] != null)
        {
            Response.Write(Session["Username"].ToString());
        }
    }
}




Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>