Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, September 18, 2017 11:15 AM
Hello, friends.
I need your help.
Visual Studio 2013.
In File - New - Web Site I make a new site named TEST. This site have a 2 pages - Page1 and Page2.
Page1 have 1 TextBox and 1 Button.
Page2 have 1 TextBox.
Idea is to sign a number in TextBox /Page1/, click Button and view result /my number * 3.14/ in TextBox in Page2. That's all. I don't know how to redirecting the result to Page2.
Thanks in advance.
All replies (10)
Monday, September 18, 2017 5:26 PM ✅Answered
Here is a good article with examples. I recommend you try the "Getting Post Information from the Source Page".
https://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
Matt
Monday, September 18, 2017 7:27 PM ✅Answered
try to do this in VB
You can use below code if you are using VB.Net
**Page 1 **
HTML
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:Button ID="bntRedirect" runat="server" Text="Redirect" />
VB.Net
Protected Sub bntRedirect_Click(sender As Object, e As EventArgs) Handles bntRedirect.Click
'Redirecting with value from textbox
Response.Redirect("Page2.aspx?Value=" + TextBox5.Text)
End Sub
Page 2
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Read the value from query string
Dim value As Integer = Integer.Parse(Request.QueryString("Value"))
TextBox1.Text = Convert.ToString(value * 3.14)
End Sub
Monday, September 18, 2017 4:00 PM
how to redirecting the result to Page2.
You can use Response.Redirect to redirect to page2 on button click
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("Page2.aspx");
}
Make you have provided the path for your page2.aspx properly
Monday, September 18, 2017 4:07 PM
Idea is to sign a number in TextBox /Page1/, click Button and view result /my number * 3.14/ in TextBox in Page2.
On option is to use QueryString to pass values between page 1 to page 2
Page 1
HTML
<asp:Button ID="btnRedirect" runat="server" Text="Redirect" OnClick="btnRedirect_Click" />
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
C#:
protected void btnRedirect_Click(object sender, EventArgs e)
{
//Redirecting with value from textbox
Response.Redirect("Page2.aspx?Value=" + TextBox5.Text);
}
page 2
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Result
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
C#:
protected void Page_Load(object sender, EventArgs e)
{
//Read the value from query string
int value = int.Parse(Request.QueryString["Value"]);
TextBox1.Text = Convert.ToString(value * 3.14);
}
Monday, September 18, 2017 4:09 PM
I suggest that you click the Learn link above and go through a few tutorials related to the technology you are trying to learn.
I'm guessing you need an ASP Web Forms sample.
Page1
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Page1.aspx.cs" Inherits="WebFormsDemo.Page1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Pi" runat="server"></asp:TextBox>
</div>
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</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;
namespace WebFormsDemo
{
public partial class Page1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Page2.aspx?Pi=" + Pi.Text);
}
}
}
Page 2
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Page2.aspx.cs" Inherits="WebFormsDemo.Page2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="PiRedirect" runat="server"></asp:TextBox>
</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;
namespace WebFormsDemo
{
public partial class Page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["Pi"] != null)
{
PiRedirect.Text = Request.QueryString["Pi"];
}
}
}
}
Duplicate thread
https://forums.asp.net/p/2128925/6166523.aspx?Redirecting+and+view+result+in+another+page
Monday, September 18, 2017 6:27 PM
Thank you.
Monday, September 18, 2017 6:54 PM
Thank you.
I try to do this in VB, not in C#.
Redirection to Page2 work. All other is so complicated for me.
Tuesday, September 19, 2017 2:59 AM
Hi vesodimov,
I can see that you had created a duplicate thread for the same issue.
which you mark as an answer.
so it looks like your issue is solved.
this duplicate thread is still open.
I suggest you to mark this thread also as an answer and close it.
Reference:
Redirecting and view result in another page
further , I want to suggest you that don't create duplicate threads for the same issue.
Regards
Deepak
Tuesday, September 19, 2017 5:50 AM
YES ! Work !
Thank you !
Tuesday, September 19, 2017 5:51 AM
Sorry about that.
Will not be repeated.