Solved

Cross-Page Post Back problem

Posted on 2006-10-27
5
533 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…

713 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