Solved

Cross-Page Post Back problem

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now