Hy all,

I am sure its very simple thing and I am not just getting it, I am trying to send textbox value from one page to another and its keep giving me an error, basicaly its not finding the class I created in previous page. My web pages are inherited from Master pages so that might be a problem. My code on First page is as follows

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Members_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int chid;
        chid = Convert.ToInt32(DetailsView1.Rows[0].Cells[1].Text);
        TextBox1.Text = chid.ToString();
    }
    public string meetingID
    {
        get
        {
            return Convert.ToString(TextBox1.Text);
        }

    }

My Code on Target page is as follows.
Html code

<%@ Page Title="" Language="C#" MasterPageFile="~/Members/MasterPage.master" AutoEventWireup="true" CodeFile="invitemem.aspx.cs" Inherits="Members_Default" %>
<%@ PreviousPageType VirtualPath="~/Members/Members.aspx"%>

c# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Members_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       Pre_meetingid.Text = PreviousPage.meetingID; //Here I am getting Error on meetingID as ASP.net doesnt contain definition of meetingID
        //if (PreviousPage != null)
       // {
        //  ContentPlaceHolder cp = Page.PreviousPage.Form.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
         // if (cp != null)
         // {
          //    TextBox tb = cp.FindControl("TextBox1") as TextBox;
           //   if (tb != null)
            //  {
            //      Pre_meetingid.Text = tb.Text;
            //  }
          //}
      //  }
  }
}

I have also tried second way which is being commented and the returns no value.

Any Idea where I am going wrong or do we need any other assembly apart from Html code one?

Thanks in advance.

Gibz

Recommended Answers

All 4 Replies

I am not the best to answer this but I don't think you can call a method from another page. But you can get the value from the textbox from a previous. So if the value you need is in TextBox1 on the previous page you can try this.

TextBox myBox = (TextBox)PreviousPage.FindControl("TextBox1");
 if (myBox.Text != null)
    Label2.Text = myBox.Text;
 else
    Label2.Text = "Nothing was in textbox";

>I am trying to send textbox value from one page to another and its keep giving me an error

Query string

string val=TextBox1.Text;

Response.Redirect("page2.aspx?val=" + val);

Yup worked, great Thankyou. Link was really usefull.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.