System.NullReferenceException - Calling secondary page
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(ob开发者_JAVA百科ject 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
- Components(folder)
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.
精彩评论