Link to home
Start Free TrialLog in
Avatar of JasonWinn
JasonWinn

asked on

Cross-Page Post Back problem

Hello,

I am simply trying to pull the information from one page to another. When I run my script I get this error:

Object reference not set to an instance of an object:
 TextBox output = (TextBox)Page.PreviousPage.FindControl("companyBox");

Thats the error, the following is a portion of my code:

<%@ PreviousPageType VirtualPath="~/default.aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    public void submitButton_Click(object sender, EventArgs e)
    {
       
        TextBox output = (TextBox)Page.PreviousPage.FindControl("companyBox");
        notesBox.Text = "Hello, " + output.Text;
   }
       
</script>
Avatar of Roopesh_7
Roopesh_7

I THINK ITS NOT POSSIBLE IN ASP.NET ... query string to get the values....
ASKER CERTIFIED SOLUTION
Avatar of avanishp
avanishp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JasonWinn

ASKER

Hey Avanish,

Thank you for the reply.

I tried doing what you had but no go. First of all, it says .Value is invalid so I have been using .Text.

I am not getting any error messages, and notesBox.Text is displaying "Hello, " but it is not displaying hiddenCompany.Text's text.

any ideas? I will also include companyBox's code

statusNotifyMngment.aspx:

    public void submitButton_Click(object sender, EventArgs e)
    {
        notesBox.Text = "Hello, " + hiddenCompany.Text;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            TextBox output = (TextBox)Page.PreviousPage.FindControl("companyBox");
            //hidCompany hidden field to take previous page control value
           
            hiddenCompany.Text = output.Text;
        }

Default.Aspx:

<asp:TextBox ID="companyBox" runat="server" ></asp:TextBox>
<asp:Button ID="notifyButton" runat="server" Text="Notify" Width="74px" CssClass="button" PostBackUrl="~/statusNotifyMngment.aspx" />
Update:

I have changed around some things but still not working. Looking for any help possible.

My textbox is showing "Didnt work" when I run this. I am using public properties on the 1st page

Default.aspx

<script runat="server">
       
        public String CurrentCompany
        {
            get
            {
                return companyBox.Text;
            }
        }

</script>

statusNotifyMngment.aspx: (page 2)

        if (PreviousPage != null && PreviousPage.IsCrossPagePostBack)
        {
            notesBox.Text = PreviousPage.CurrentCompany.ToString();
        }
       
        else
        {  
              // if previous Page is NULL just redirect us
            notesBox.Text = "Didnt Work";
                   
        }  
Small mistake, I did not mean to include ToString in the IF Statement. WIthout ToString() it still does not work