Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How do I pass a string from one aspx file to another?

How do I pass a string from one aspx file to another?

Scheduled Pinned Locked Moved ASP.NET
questioncsharpasp-nettutoriallearning
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ranger49
    wrote on last edited by
    #1

    Hello! I have a nice book on ASP.NET but it doesn't explain how to for instance transfer data like a string from one aspx file to another. What I want to do is enter a string in Default.aspx and then pass that string to Default2.aspx, so that the string can be used in Default2.aspx.cs I tried a lot of things, but they were all guesses. Could someone give me some pointers? Ranger. Novice

    D 1 Reply Last reply
    0
    • R Ranger49

      Hello! I have a nice book on ASP.NET but it doesn't explain how to for instance transfer data like a string from one aspx file to another. What I want to do is enter a string in Default.aspx and then pass that string to Default2.aspx, so that the string can be used in Default2.aspx.cs I tried a lot of things, but they were all guesses. Could someone give me some pointers? Ranger. Novice

      D Offline
      D Offline
      Dave Herren
      wrote on last edited by
      #2

      Here's a start. How to pass data between ASP.NET pages [^] Submitting Web Form data from one ASP.NET page to another[^]

      topcoderjax - Remember, Google is your friend. Try this Custom Google Code Search

      R 1 Reply Last reply
      0
      • D Dave Herren

        Here's a start. How to pass data between ASP.NET pages [^] Submitting Web Form data from one ASP.NET page to another[^]

        topcoderjax - Remember, Google is your friend. Try this Custom Google Code Search

        R Offline
        R Offline
        Ranger49
        wrote on last edited by
        #3

        Default.aspx.cs protected void Button_Click(object sender, EventArgs e) { Context.Items["SourceLabel"] = SourceLabel.Text; Server.Transfer("Default2.aspx"); } Default2.aspx.cs protected void Page_Load(object sender, EventArgs e) { TargetLabel.Text = (string)Context.Items["SourceLabel"]; } This should work, but it doesn't. Did I forget something? Ranger. Novice.

        R 1 Reply Last reply
        0
        • R Ranger49

          Default.aspx.cs protected void Button_Click(object sender, EventArgs e) { Context.Items["SourceLabel"] = SourceLabel.Text; Server.Transfer("Default2.aspx"); } Default2.aspx.cs protected void Page_Load(object sender, EventArgs e) { TargetLabel.Text = (string)Context.Items["SourceLabel"]; } This should work, but it doesn't. Did I forget something? Ranger. Novice.

          R Offline
          R Offline
          Ranger49
          wrote on last edited by
          #4

          All I am trying to do is pass a string from Default.aspx to Default2.aspx, and it just doesn't seem to work!!! Ranger. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ClassName="_Default" %> public partial class _Default : System.Web.UI.Page { public string message { get { return BronLabel.Text; } } protected void Page_Load(object sender, EventArgs e) { } protected void Button_Click(object sender, EventArgs e) { Server.Transfer("Default2.aspx"); } In Default2.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <%@ Reference Page="~/Default.aspx" %> public partial class Default2 : System.Web.UI.Page { _Default sourceClass; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { sourceClass = (_Default)Context.Handler; :confused:<<< exception cannot cast DoelLabel.Text = sourceClass.message; } } } Novice

          D 1 Reply Last reply
          0
          • R Ranger49

            All I am trying to do is pass a string from Default.aspx to Default2.aspx, and it just doesn't seem to work!!! Ranger. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ClassName="_Default" %> public partial class _Default : System.Web.UI.Page { public string message { get { return BronLabel.Text; } } protected void Page_Load(object sender, EventArgs e) { } protected void Button_Click(object sender, EventArgs e) { Server.Transfer("Default2.aspx"); } In Default2.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <%@ Reference Page="~/Default.aspx" %> public partial class Default2 : System.Web.UI.Page { _Default sourceClass; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { sourceClass = (_Default)Context.Handler; :confused:<<< exception cannot cast DoelLabel.Text = sourceClass.message; } } } Novice

            D Offline
            D Offline
            Dave Herren
            wrote on last edited by
            #5

            At a glance you seem to be relying on server.transfer, which, when properly execute, will make the query string and any form variables from default available to default2. try changing Server.Transfer("Default2.aspx") to Server.Transfer("Default2.aspx", true); Here is an article on this: Server.Transfer Vs. Response.Redirect[^]

            topcoderjax - Remember, Google is your friend. Try this Custom Google Code Search

            R 1 Reply Last reply
            0
            • D Dave Herren

              At a glance you seem to be relying on server.transfer, which, when properly execute, will make the query string and any form variables from default available to default2. try changing Server.Transfer("Default2.aspx") to Server.Transfer("Default2.aspx", true); Here is an article on this: Server.Transfer Vs. Response.Redirect[^]

              topcoderjax - Remember, Google is your friend. Try this Custom Google Code Search

              R Offline
              R Offline
              Ranger49
              wrote on last edited by
              #6

              TopCoderJax wrote:

              Server.Transfer("Default2.aspx", true);

              Tried it it didn't work and I didn't get the message associated with the bug. Will read the article you posted, thanks! I was thinking, could it be because the 'sender' is the Default.aspx that it won't work? Will try some more tomorrow. Thanks, Ranger. Novice

              R 1 Reply Last reply
              0
              • R Ranger49

                TopCoderJax wrote:

                Server.Transfer("Default2.aspx", true);

                Tried it it didn't work and I didn't get the message associated with the bug. Will read the article you posted, thanks! I was thinking, could it be because the 'sender' is the Default.aspx that it won't work? Will try some more tomorrow. Thanks, Ranger. Novice

                R Offline
                R Offline
                Ranger49
                wrote on last edited by
                #7

                Tried it, and it works now! Thanks!:-D Ranger. Novice

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups