BindData() - may I call it manually within Page_Load()?

R

Rudi Hausmann

Hi!

When is BindData() usually called?
Is it OK to call it within Page_Load() so that I have the content of the
bound controls?

Thanks

Rudi
 
M

Mark Rae

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
}
 
R

Rudi Hausmann

Rudi said:
Hi!

When is BindData() usually called?
Is it OK to call it within Page_Load() so that I have the content of the
bound controls?

Thanks

Rudi

Oops, I ment DataBind() of course. Sorry for the confusion...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top