Solved

Cross-Page Post Back problem

Posted on 2006-10-27
5
525 Views
Last Modified: 2008-01-09
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>
0
Comment
Question by:JasonWinn
  • 3
5 Comments
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 17822831
I THINK ITS NOT POSSIBLE IN ASP.NET ... query string to get the values....
0
 
LVL 4

Accepted Solution

by:
avanishp earned 500 total points
ID: 17824785
I think you are using  Page.PreviousPage.FindControl("companyBox"); on button click event which resubmit page.. so Page.PreviousPage will unll in that case. So you have to save that value in some hidden field at page load.  That hidden field value you can use in button click event
in page load:
 if (PreviousPage != null)
 {
      TextBox output = (TextBox)Page.PreviousPage.FindControl("companyBox");
      //hidCompany hidden field to take previous page control value
       hidcomany.Value= output.Text;
 }
 public void submitButton_Click(object sender, EventArgs e)
    {
       
         notesBox.Text = "Hello, " + hidcomany.Value;
   }

I hope it will help you.
Avanish
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 17834627
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" />
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 17836236
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";
                   
        }  
0
 
LVL 3

Author Comment

by:JasonWinn
ID: 17836292
Small mistake, I did not mean to include ToString in the IF Statement. WIthout ToString() it still does not work
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question