Home

Thursday, 14 July 2016

Send Data from One page from another page without using state Management(Cookies,Session) Using c# Asp.net

Step 1) Create Form as a previous Post Name is WebForm1.aspx and write below code on Button Click-
 public string Id { get { return TextBox1.Text; } }
        public string Name { get { return TextBox2.Text; } }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Server.Transfer("WebForm2.aspx");
        }
Step 2-Create another web Form where display Input Data name is webForm2.aspx and addbelow code in Form Body-
 <form id="form1" runat="server">
        <table class="auto-style1">
            <tr>
                <td>ID</td>
                <td>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>Name</td>
                <td>
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                </td>
            </tr>
        </table>
    </form>
Step 3-Write Below code in WebForm2.aspx.cs in PageLoad method.
 protected void Page_Load(object sender, EventArgs e)
        {            
            if (!IsPostBack)
            {
                Page LastPage = (Page)Context.Handler;
                if (LastPage is WebForm1)
                {
                    Label1.Text = ((WebForm1)(LastPage)).Id;
                    Label2.Text = ((WebForm1)(LastPage)).Name;
                }
            }
        }
 Step 4-Run application after that we get form1 pass data in form2 after enterning input in textbox and click on Button

No comments:

Post a Comment