Master Page databinding issue

A

Alan Samet

I know what's causing this, but how do I work around it?

**********************
file: test.master:
**********************

<%@ Master %>
<script runat=server>
void Page_Load(object sender, EventArgs e)
{
DataBind();
}
</script>
**<asp:ContentPlaceHolder runat=server id=main />**

**********************
file: test.aspx
**********************

<%@ Page MasterPageFile="test.master" %>
<script runat=server>
public override void DataBind()
{
throw new Exception();
}

string Expression = "I am Databound";
</script>
<asp:Content runat=server contentplaceholderid=main>
<%# Expression %>
</asp:Content>

**********************
Problem
**********************

DataBind is never called on the aspx file, yet databinding expressions
are still processed. I imagine what's happening is this:

Master page finds all the <asp:content ...> controls in the page file.
Removes them and loads them into the master page a la:

foreach(Control c in LoadedPage.Controls)
{
Content content = c as Content;
if (content == null) continue;

this.FindControl(content.ContentPlaceHolderID).Controls.Add(content);
}

//discard the (aspx) page loaded into memory

DataBind the master page.

There is one thing that I'm missing, and that is if I manually call
"DataBind()" within the page, that databind expression is called as
well. I can't call DataBind() at both the master and the page level
without having it fire twice. Did Microsoft give us a delegate that I
can wire up to to get around this?

-Alan
 
M

Mischa Kroon

There is one thing that I'm missing, and that is if I manually call
"DataBind()" within the page, that databind expression is called as
well. I can't call DataBind() at both the master and the page level
without having it fire twice. Did Microsoft give us a delegate that I
can wire up to to get around this?

A bit of un asked for advice, it seems to be better to databind things
individually rather then using a global databind event.

like:

Datagrid1.DataSource = datatable1
Datagrid1.DataBind()

This way you will avoid any unwanted triggering of the DataBind.
 

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
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top