Reputation: 1346
I have piece of code:
protected void Page_Load(object sender, EventArgs e)
{
_SearchResult.GridViewChanged += _SearchResult_GridViewChanged;
}
public Control GvControls { get; set; }
protected void _SearchResult_GridViewChanged(object sender, Orders.GridViewChangedEventArgs e)
{
this.GvControls = e.GControl;
}
protected void export_ServerClick()
{
new ExportGridView(this.GvControls,"report");
}
One control generate a event with event arg and push a control by arg, then other (this) control do some push-ups with this arg
and when am i try to do push export_ServerClick()
property GvControls
equals null but before whould be not null. Why is it happening.
ThankX
Upvotes: 1
Views: 195
Reputation: 460268
All variables (and even controls) are disposed at the end of the page's lifecycle. That's the reason why you have to recreate all dynamically created controls on postback. For the same reason you have to re-initialize a variable with the desired value.
So i assume that the GridViewChanged
-event is triggered first. Then the user clicks another button that triggers the export_ServerClick
-event handler. At this point the field GvControls
has gain it's default value which is null
.
You have to persist this value somewhere, for example in the Session
.
Nine Options for Managing Persistent User State in Your ASP.NET Application
However, i think that you should not need to persist the contol itself. Perhaps it is sufficient to store the ID of the control. Maybe it's even better to load it again from the datasource before you export it for two reasons:
Upvotes: 1