Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
it's several input element like checkbox and text type in page1.aspx that i want access their properties(value for text type and checked property for checkbox and their names) in page_load event of another page.aspx.cs,how can i do without
C#
session["x"]
or
C#
.findcontrol("x")
and
C#
Request.["x"]
solution?

thanks all

What I have tried:

request.form["x"]
findcontrol("x")
Posted
Updated 11-Jul-16 2:25am

Those two pages are live in a different universe, so no simple cross-access between them...
Using the Session object can be a solution (if it is granted, that you have the same session between the two pages), but for that you first have to put those values on the session...
You also have to ask yourself: do I always use page2 AFTER page1?
If the answer is 'yes' you can use the old and good submit target of HTML to pass the values...That will pass all hidden fields to the target page as QueryString values...
<form> - HTML | MDN[^]
 
Share this answer
 
v2
Comments
mohamadMahmodi 10-Jul-16 7:13am    
form1(page1) is known in page2.cs intellisense ,i can send values via session but why form1 is known in page2.cs ,it seems that is a way to access form1 elements?
(yes,always run page2 AFTER page1 and platform is c# asp.net webform)
pparya27 11-Jul-16 8:17am    
let it be known.. but it will be have value when its object is created. once the server has send form1 to the client, it forgets about it. so if you want form2 to know some data from form1, then you must store in somewhere like session, cookies or database.
Kornfeld Eliyahu Peter 11-Jul-16 8:33am    
...or you can post that data directly from the client of page1 to the sever of page2...
At runtime, form1 does not exist while form2 is being displayed. HTTP works over a request/response setup. The browser makes a request, the server returns the requested page. The connection dies at that point and the server forgets you even exist.

If you requested Form2, Form1 never comes into the request/response process at all. It doesn't exist. Therefore, if you need to pass a value from Form1 to Form2, you have to save that value somewhere after a form on Form1 is submitted to the server. The server can either save that value is a Session object or in a database or some other storage for use in a later request. It's also possible for the servers response to the form submission to respond with Form2 and use the value from the Form1 submission.
 
Share this answer
 
Have a look :

Form1 :
=======

ASP.NET
<form id="form1" runat="server">
  <div>
      <asp:Label ID="lblForm1" runat="server" Text="Form 1 Data"></asp:Label>&nbsp;&nbsp;
      <asp:TextBox ID="txtForm1" runat="server"></asp:TextBox>&nbsp;&nbsp;
      <asp:Button ID="btnForm1" runat="server" Text="Button" onclick="btnForm1_Click" />

  </div>
  </form>


C#
protected void btnForm1_Click(object sender, EventArgs e)
   {
       Session["data1"] = txtForm1.Text;
       Response.Redirect("Form2.aspx");
   }



Form2 :
=========

ASP.NET
<form id="form2" runat="server">
<div>

    <asp:Label ID="lblForm2" runat="server" Text="Form 2 Data (from session variable)"></asp:Label>&nbsp;&nbsp;
    <asp:TextBox ID="txtForm2" runat="server"></asp:TextBox>&nbsp;&nbsp;

</div>
</form>



C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["data1"] != null)
        {
            txtForm2.Text = Session["data1"].ToString();
        }
    }
 
Share this answer
 

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