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

How do i correctly implement !isPostback?

I have a huge application and I notice that when the user makes a selection from a drop-down or clicks a button, the data is not reloaded.  The only time the page is reloaded is when I click the actual navigation button for the page.  I also have a label that displays record count or error messages which does not clear unless I select a navigation button. I know that there has to be a better way.  How do i know when to include !isPostback?  

for example, below is an event for a button click.  errorlabel displays error data as well as recordcount.  how would I make sure that if the user reselected the initial drop-down and then re-selected the button, that other data was cleared?

=========================

 protected void initSearchbtn_Click(object sender, EventArgs e)
    {
             int topSearch = Convert.ToInt32(searchFunc.SelectedIndex);
            if (topSearch == 0) //tapes
            {
                tapeGrid.Visible = true;
                bindOpenTapeReqs(); //contains errorLbl.Text
                mainGrid.Visible = false;
                dubdetailsgrid.Visible = false;
            }
            if (topSearch == 1) //dubs, includes dubs awaiting completion
            {
                BindDubsMaster(); //errorLbl.Text
                BindopenDubDet();//errorLbl.Text
                BindDubbedDubs();//errorLbl.Text
            }          
    }
0
synergeticsoul
Asked:
synergeticsoul
  • 2
  • 2
1 Solution
 
lunadlCommented:
Could you clarify a little, please
0
 
synergeticsoulAuthor Commented:
when the user selects a record from a gridview or inputs data, after they submit the information, some of the information remains.  this is especially true with my gridviews.  i am under the impression that this has something to do with using !isPostback.  how would I correctly implement !isPostback. I read somewhere that developers use this throughout their code.
0
 
lunadlCommented:
Developers do use this throughout their code. The server loads the page every time there is a web request to a page. Usuallly there is a function or routine that needs to be performed only if it is a new request, that is : if(!isPostback) --> the page is not a postback, so it is an intial load. The alternative is if the page is a postback from a button action, form submission or an element that performs and autopostback. The post back sends back to the server the information revealing what element issued the post back to the server and all the normal httprequest information. During this time you may only want to update the gridview or skip a function that checks for cookies; anything that does not need to be done on an update to the page. This will go in an if(isPostback). an example of when you would use this is if you were programmatically setting a textbox each time the page was loaded.
psuedocode:
page_load()
{

if(!isPostback)
{
  //the initial load set the value to 1
mytb.text = 1;
}
if(isPostback)
{
  //no longer the intial load, so we can reset the value back to 1 again or we will lose count, so it goes in here to update
mytb.text +=1;
}

}
0
 
synergeticsoulAuthor Commented:
THANK YOU lunadl!!!!!!!!!!!!!!!!!!!!!!!!!!!!  Your explanation has been a tremendous help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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