0

I'm passing the value to the next page using server.execute, but I'm unable to get that value into next page.

//this is WebForm1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Execute("WebForm2.aspx");
    }




//this is WebForm2.aspx.cs
protected void Page_Load(object sender, EventArgs e)
       {
           Label1.Text = //what method should i use to get the vale from WebForm1.aspx.cs
       }
  • Similar question (and answers) found via google pointing to Stackoverflow: https://stackoverflow.com/questions/8324731/passing-a-parameter-through-server-execute – Epistaxis Jul 31 '19 at 14:12
  • 1
    you can use session like this Session("Something") = 123 and then in your page load Label1.Text =Session("Something"); – Amine Jul 31 '19 at 14:12
  • Try this ... Look here for encode-decode : https://stackoverflow.com/questions/13445121/asp-net-query-string-encoding-and-decoding – Gurcan Jul 31 '19 at 14:31
  • @Gurcan querystring will not apply here - it's using server.execute, not response.redirect, so a new HTTP request will not be made. – ADyson Jul 31 '19 at 15:36
  • I agree with Amine, Session is probably the way to go with this. – ADyson Jul 31 '19 at 15:37

1 Answers1

1

Edit :

On page1 (Button click etc) : Server.Execute("page2.aspx?v=" + YourEncryptFunction(TextBox1.Text));

On page2 (Page_Load) : TextBox1.Text = YourDecRyptFunction(Request.QueryString[0]);

Gurcan
  • 105
  • 7
  • The question is about ASP.NET, not ASP Classic. The concept of "includes" does not apply at all in ASP.NET. Are you sure you understand this topic? (Also, OP makes no mention that the value they are talking about is from the querystring...more likely it's a posted value from a textbox or something). – ADyson Jul 31 '19 at 16:24
  • @ ADyson, yes, I think I understood the question. I didn't notice that the link I gave was classic asp. Please accept my apology. On the other hand, I tried to open an aspx project and send a value to another aspx page with QueryString and Server.Execute method and I didn't have any problems. If it doesn't work, maybe it's related to your IIS installation or settings. – Gurcan Jul 31 '19 at 17:00
  • No need to apologise, but thanks. Anyway it's not about my settings, I'm not the one who asked the question, and I have not tried to run the code. I didn't say the querystring idea would not work, I simply pointed out that the question doesn't mention it. On balance the wanted value is more likely to be coming from a field on the page, since this is happening in response to a button click, which will generate a POST request. Probably worth asking the original asker for clarification of exactly where the data is coming from, before committing to an answer – ADyson Jul 31 '19 at 18:01