When is BindData() usually called?
I assume that BindData() is a custom method you have written to fetch a
collection of data from your database which is then bound to various web
controls...?
If so, you call it whenever it's needed...
Is it OK to call it within Page_Load() so that I have the content of the
bound controls?
Absolutely! However, you will almost certainly want to enclose it in a if
(!isPostBack) loop so that it doesn't get run twice, especially if e.g. you
have a method which updates data in response to a button click...
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void cmdSave_Click(object sender, System.EventArgs e)
{
// save the data...
BindData();
}
private void BindData()
{
// fetch the data from the database
}