0

my component (ascx):

This component is part of my page, with him, i open one new page (the next code).

    public void LoadSeller(string name, string id)
    {
        this.txtSeller.Text = name;
        this.hdnSellerID.Value = id;
    }

my pop up (aspx):

With this code i made some search and select one item on GridView, sending this back to my ascx.

    protected void btnSave_Click(object sender, EventArgs e)
    {
        Components.BasicData basicData= new Components.BasicData();

        Button save = (Button)sender;
        basicData.LoadSeller("TEST", save.CommandArgument);
    }

The post back works, i'm receiving the right data (i checked with my debug). but the txt and hidden are both null (like they are not loaded), they are working without my pop up, but i need mine pop up.

Any ideas ?

PS: My viewState is UP.

I debug my entire code and it stopped at

this.txtSeller.Text = name;

First line of LoadSeller. This said that "this.txtSeller" is null, and i don't know why. i checked my .designer.cs and this.txtSeller is declared. (it also work if i'm not trying load from other page)

Obs: I was wondering if maybe my code is somehow destroying the load (or something like this) on my other page.

Thanks for your help ^.^

EDIT:

My structure is this:

PAGE

Control1

Control2

    **Open pop up**

Control3

POP UP

Search

Gridview with buttons

Button in gridview

Goes to my second code "my pop up (aspx):"

Close pop up

in my Control2 i have my first code "my component (ascx):"

Subtitle: Control == userControl

Breadcrumb navigation:

  • Solution
    • Components(folder)
      • BasicData.ascx
    • PopUp.aspx
Michel Ayres
  • 5,891
  • 10
  • 63
  • 97
  • What is `Components.BasicData`? If it is the UserControl you should load it with `Page.LoadControl("BasicData.ascx")` if you want to add it dynamically or reference it directly if it's already on the page. – Tim Schmelter Apr 06 '11 at 20:47
  • Thanks Tim, for your answer ^.^ i Tried use `Components.BasicData`, before this line `Components.BasicData basicData= new Components.BasicData();` and this didn't work. – Michel Ayres Apr 07 '11 at 12:37

1 Answers1

1

This line Components.BasicData basicData= new Components.BasicData(); is NOT create the custom control and all the inside controls of him, nether is a pointer to the existing ones.

If you all ready include your control on this page, then you can direct call this function it by its id of the control. This control all ready exist together with your page, just call it.

protected void btnSave_Click(object sender, EventArgs e)
    {
        Button save = (Button)sender;
        YourCustomControlID.LoadSeller("TEST", save.CommandArgument);
    }

Now if you wish to send data to the next page you first create a class that keep your information and its going to move from page to page and fill with data.

In every page you have a reference to this class, a variable, that ether create a new ether get it from the previous page. You store it on ViewState

Now from Page1 -> Page2.

You send it from Page1 by set to the

PostBackUrl="Page2.aspx"

On page2.aspx you set where you can get informations

<%@ PreviousPageType VirtualPath="~/Page1.aspx" %>

and you get them by...

if (Page.PreviousPage != null)
{
    if(Page.PreviousPage.IsCrossPagePostBack == true)
    {
        GetTheClass = PreviousPage.MyDataClass;
    }
}

And one other manual way is to make your class seriable, send it as xml via post, and decode it on the next page.

Aristos
  • 66,005
  • 16
  • 114
  • 150
  • I'm trying, in my sample, your first method (but making it an object first, then working with the object). this send my data, as i said, but give me the `NULL` error. i'll try the class that you suggest. Anyhow +1 for you explanation, good post. (i'm not accepting as answer, yet, because, i don't know if it will work for me.) – Michel Ayres Apr 07 '11 at 12:49
  • @Nymos Yes I think the second way is the one you need. You can call from the PreviousPage and functions and probably you can call your function - you only need to make some tests to see. – Aristos Apr 07 '11 at 13:46