Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
I have a query related to posting values from HOMEPAGE to 2/3 other pages in background.

e.g.: If user clicks on a link the same values must go to multiple pages

User clicks on a link X which will post values x=1, y=2, z=3

So in HOMEPAGE we get these values x=1, y=2, z=3

NOW I want the same values
C#
x=1, y=2, z=3
to be available in other pages of the site page1.aspx.cs and page2.aspx.cs

So how can i pass values from Homepage to Page1.aspx.cs and page2.aspx.cs


I've already tried sending using session / response.write from the homepage, but the values are not available in Page1.aspx.cs and page2.aspx.cs

In page 2
C#
protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    Response.Write("Ths is the response from two.aspx: " + Request.Form["MyData"]);
    Response.End();
}


Where I see the value in page1.aspx.cs or page2.aspx.cs I see MYdata= " " NULL

in Default page

C#
<asp:TextBox ID="txtData" runat="server" />
<asp:Button ID="cmdSend" Text="Send" runat="server" />
<div id="resulta"></div>
<div id="resultb"></div>
 
<script type="text/javascript">
    function sendData(txt)
    {
        var c = $("#" + txt);
 
        makeCall("<%=Page.ResolveUrl("~/one.aspx") %>", c.val(), $("#resulta"));
        makeCall("<%=Page.ResolveUrl("~/two.aspx") %>", c.val(), $("#resultb"));
 
        return false;
    }
 
    function makeCall(url, text, target)
    {
        $.ajax({
            type: "POST",
            url: url,
            data: { myData: text },
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            dataType: "text",
            success: function (data) {
                target.html(data);
            }
        });
 
    }
</script>
Posted
Updated 21-Jan-16 14:34pm
v2
Comments
Cyrus_Vivek 20-Jan-16 23:08pm    
Can you share what have you tried and where exactly you are getting problem?
Avik Ghosh22 21-Jan-16 0:36am    
you can store data either cookies or session to send data from one page to other pages .
aarif moh shaikh 21-Jan-16 1:16am    
use session for this
Sinisa Hajnal 21-Jan-16 2:53am    
Session.
F-ES Sitecore 21-Jan-16 7:00am    
What's going to happen in the browser? Do you redirect the user to one of these pages? Or do you just want the data sent in the background? Or do you want the pages to open in new windows\tabs? You'll need to give a bit more information on what it is you're trying to achieve.

Hi,

First of all question is not clear about what you want and what have you tried to resolve your problem.

You have few options as per my understanding. Using Query string is one among them.

Using a Query String:
When you use a hyperlink or Response.Redirect to navigate from one page to another, you can add information in a query string at the end of the URL.

1. In the source Web Forms page when you specify the URL of the target page, include the information that you want to pass in the form of key-value pairs at the end of the URL. The first pair is preceded by a question mark (?) and subsequent pairs are preceded by ampersands(&), as shown in the following example:
http://contoso.com/products.aspx?field1=value1
http://contoso.com/products.aspx?field1=value1&field2=value2


2. In the target page, access query string values by using the QueryString property of the HttpRequest object, as shown in the following example:

C#
String s = Request.QueryString["field1"];


Using Session State:
Information in session state is available to all ASP.NET Web Forms pages in the current application. However, session state takes server memory, and the information is stored until the session expires, which can be more overhead than you want for simply passing information to the next page.

To use session state to pass information
1. In the source page, save the information that you want to pass in session state, as shown in the following example:
C#
Session["field1"] = "value1";


2. In the target page, read the saved information from session state, as shown in the following example:
C#
string field1 = (string)(Session["field1"]);


Reference:
How to: Pass Values Between ASP.NET Web Forms Pages[^]
 
Share this answer
 
One.aspx code-behind

C#
protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    Response.Write("Ths is the response from one.aspx: " + Request.Form["MyData"]);
    Response.End();
}



Two.aspx code-behind

C#
protected void Page_Load(object sender, EventArgs e)
{
    Response.Clear();
    Response.Write("Ths is the response from two.aspx: " + Request.Form["MyData"]);
    Response.End();
}


Default.aspx code-behind

C#
protected void Page_Load(object sender, EventArgs e)
{
    cmdSend.OnClientClick = string.Format("return sendData('{0}')", txtData.ClientID);
}


Default.aspx (needs reference to jQuery too)

ASP.NET
<asp:TextBox ID="txtData" runat="server" />
<asp:Button ID="cmdSend" Text="Send" runat="server" />
<div id="resulta"></div>
<div id="resultb"></div>
    
<script type="text/javascript">
    function sendData(txt)
    {
        var c = $("#" + txt);

        makeCall("<%=Page.ResolveUrl("~/one.aspx") %>", c.val(), $("#resulta"));
        makeCall("<%=Page.ResolveUrl("~/two.aspx") %>", c.val(), $("#resultb"));

        return false;
    }

    function makeCall(url, text, target)
    {
        $.ajax({
            type: "POST",
            url: url,
            data: { myData: text },
            contentType: "application/x-www-form-urlencoded; charset=UTF-8",
            dataType: "text",
            success: function (data) {
                target.html(data);
            }
        });

    }
</script>
 
Share this answer
 
Comments
Member 12277111 21-Jan-16 15:38pm    
I'm trying this solution but when its coming here
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.Write("Ths is the response from two.aspx: " + Request.Form["MyData"]);
Response.End();
}

to page one Request.Form["mydata"] the value out here becomes NULL....
F-ES Sitecore 22-Jan-16 3:44am    
You're not supposed to navigate to those pages in the browser, the js calls the page via ajax and processes the results. Those pages will be whatever you currently have in one.aspx and two.aspx, you didn't say what those pages were or what they did or what they returned so I knocked up dummy versions that were the simplest I could do, just to get the example working.
Member 12277111 22-Jan-16 12:56pm    
Sorry for that.. and thats my mistake.
practically I'm not navigating to that file, but they do indirectly get loaded to the page.....

I wish I could add images in here to show you how exactly they are linked up... Unfortunately I will try my best to explain Sitecore..

public void ProcessRequest(HttpContext context)
{

//Response.Write(Hiddenfilename.Value);
try
{

if (context.Request.QueryString["Download"] != null)
{
context.Response.AddHeader("Content-disposition", "attachment; filename=" + context.Request.QueryString["Download"].Split('/')[1].ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.TransmitFile(Server.MapPath(context.Request.QueryString["Download"].ToString()));
context.Response.End();
}

else
{

//Capture File From Post
HttpPostedFile file = context.Request.Files["fileToUpload"];
// HttpPostedFile file = context.Request.Files["Hiddenfilename"];


if (context.Request.Form["Opp"] == "uploading")
{

//Or just save it locally
file.SaveAs(Server.MapPath("Convert/input.pdf"));

file.SaveAs(Server.MapPath("Convert/output.pdf"));

Startup();

context.Response.Write(ImageConverter());
}
else if (context.Request.Form["Opp"] == "appending")
{
string appPages = context.Request.Form["pages"];
string appRatios = context.Request.Form["ratios"];
string appHeights = context.Request.Form["heights"];

//Or just save it locally
file.SaveAs(Server.MapPath("Convert/append.pdf"));

context.Response.Write(AppendConverter(appPages, appRatios, appHeights));
}
else if (context.Request.Form["Opp"] == "addAttachment")
{

//Or just save it locally
file.SaveAs(Server.MapPath("Attachments/" + file.FileName));
AddAttachments(Server.MapPath("Attachments/" + file.FileName), file.FileName);

context.Response.Write(file.FileName);
}
else
{

//Or just save it locally
file.SaveAs(Server.MapPath("Images/" + file.FileName));

context.Response.Write(file.FileName);
}
}
}
catch (IndexOutOfRangeException exception)
{

if (exception.Message.Contains("evaluation"))
{
context.Response.Write(" Only 4 elements of any collection are allowed. Please get a free temporary license to test the HTML5 PDF Editor without any limitations from http://www.aspose.com/corporate/purchase/temporary-license.aspx");
}
else
{
context.Response.Write("An exception occurred during processing of your document. Please contact Aspose Support.");
}

}
catch (Exception exp)
{

context.Response.Write("An exception occurred during processing of your document. Please contact Aspose Support.");
}
}


public static string AddPage_Click(string lastpage)
{
try
{
Document doc = new Document(HttpContext.Current.Serv

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900