Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cross-Page Post Back problem

Posted on 2006-10-27
5
Medium Priority
?
556 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 2000 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

972 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