How to determine whether data is coming from previous page or withing the current page in Cross Page Posting?

Hi everyone,

My problem is:

I'm using a DataGrid in (page2.aspx) to display the search result for which I'm collecting all the search criteria from previous page(page1.aspx). Till now the task is easy. But in the second page(page2.aspx) there are some other buttons and when I'm trying to invoke methods of those button controls of page2.aspx  an error is displaying i.e. "Object reference not set to an instance of an object" and it is pointing to the code where I'm collecting data from page1.aspx. Also I'm using Masterpage concept.

 How to separate codes for displaying result based on previous page data  and own methods of current page? 

0
contactkristian
9/9/2008 12:05:37 PM
📁 asp.net.presentation-controls
📃 72751 articles.
⭐ 2 followers.

💬 6 Replies
👁️‍🗨️ 537 Views

You can access a previous page control like this:

Dim t As TextBox = CType(PreviousPage.FindControl("Textbox1"), TextBox)
Dim c As Calendar = CType(PreviousPage.FindControl("Calendar1"), Calendar)
           

Hope this helps.

0
mcr_subbu
9/9/2008 12:33:56 PM

 No, I'm using Property method to access control values of previous page and I've no problems regarding this.

My problem is how to check that if a request is coming from Page1.aspx to page2.aspx or the user directly hit the page2.axpx  to perform other task. 

So that after this checking I can separate codes of page2.aspx to perform actions needed for CrossPagePosting of page1.aspx and actions for data only related to page2.aspx both. 

Hope it helps to understand my problem better. 

0
contactkristian
9/9/2008 4:29:29 PM

 bumps !

0
contactkristian
9/10/2008 3:53:28 AM

 is anybody there to help!!

0
contactkristian
9/10/2008 7:17:49 PM

Hi contactkristian ,

I am not fully understand your question.

contactkristian:
So that after this checking I can separate codes of page2.aspx to perform actions needed for CrossPagePosting of page1.aspx and actions for data only related to page2.aspx both. 

They should can be easily separated. Different action should execute different method. Usually the CrossPagePosting action should only be written under page load event. 

Maybe you are talking about the property "IsPostBack" . If it equals true , it means "actions for data only related to page2.aspx " . If it equals false , it means first enter the page which may be caused by "CrossPagePosting " .

So maybe the code will like :

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            //corsspaging code here 
        }else{
             //click button of page2.aspx execute here 
           }
    }

 

 



Samu Zhang
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
0
Samu
9/11/2008 5:04:55 AM

Dear Samu,

 I'm implementing a online shopping system. I've two forms which are form1.aspx and form2.aspx. In form1.aspx I want to give some searching criteria for product searching operation. And all these info. will be posted to form2.aspx and the later one will display a datagrid displaying search result.

I can do the above operation. But in form2.aspx there are some buttons also which will work independently that means not dependable on the data of form1.aspx.(suppose a button will work for "Adding to Cart" for all the products displayed in the grid. This button will not work based on the data of form1, it will work on data whatever have given to form2)

I think you understand now. Also I think your codes will help me out.

BTW thanks for your reply.
 

0
contactkristian
9/11/2008 5:34:18 AM
Reply: