• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

grid control is set to null on button click

here is the deal, i have a custom grid contol (that is referenced) and a update button on a page. when the button is clicked i break into code and the grid object is null. is there something with viewstate, preinit or something else that would cause this?
ps i am newbie
thank you
jim
0
jmrasmus
Asked:
jmrasmus
  • 7
  • 6
1 Solution
 
AsishRajCommented:
you must be rebinding your grid on page load. try using this method



If Not Page.IsPostBack() Then
   'Bind Here
Else
   'Do other things here
End IF

Open in new window

0
 
AsishRajCommented:
C#


 protected void Page_Load(object sender, EventArgs e)
    {
         if (!Page.IsPostBack()) {
            'Bind Here'
         }
         'Do other Stuffs here'
}

Open in new window

0
 
jmrasmusAuthor Commented:
here is my page_load. the getregions fills a dropdownlist. also i put a breakpoint on teh if statment in the page_load and the control was already null. hope that helps.
thank you
jim
protected void Page_Load(object sender, EventArgs e)
    {
      if(!IsPostBack)
        GetRegions();
    }

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jmrasmusAuthor Commented:
what also puzzles me is that the dropdown contol maintains it's selected value.
0
 
AsishRajCommented:
where are you getting an error, be a bit more specifi
0
 
AsishRajCommented:
please post which place you are getting error
0
 
jmrasmusAuthor Commented:
"Object reference not set to an instance of an object." i just want to clairify. the grid loads and data is populated just fine. the event of the butten click first validates the grid for acceptable data. so the error occurs at the first reference to the grid.
thanks
jim
0
 
jmrasmusAuthor Commented:
to be more specific, the error happens with this this._grid.RowCount from code below.
protected void cmdSave_Click(object sender, EventArgs e)
    {
      if (this.ValidateGrid())
.
.
.
 
private bool ValidateGrid()
    {
      for (int i = 0; i < this._grid.RowCount; i++)

Open in new window

0
 
AsishRajCommented:
"Object reference not set to an instance of an object.
 
 that means you are not referencing your object correctly in your code.
0
 
jmrasmusAuthor Commented:
so what is the correct way to reference a dll so it doesn't got distroyed when postback is true? i have it referenced in the references tree and with a using statement.
thanks
jim
0
 
AsishRajCommented:
You will have to set a reference to your dll and then you should be able to call your classes from your code behind. (right click "references" in your solution explorer and choose "add reference")
0
 
jmrasmusAuthor Commented:
i did that.
thank you
jim
0
 
jmrasmusAuthor Commented:
my solution was to create a gridview control.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now