How do I pass a string from one aspx file to another?
-
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
-
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
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
-
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
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.
-
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.
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
-
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
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
-
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
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
-
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