I'm trying to fix bug in a legacy project on WEB FORMS (.Net 4). I have some logic at Layout.master (layout for pages) that use control like this:
<uc4:FooterCharity ID="NewsItemUserControl1" DataSource="<%#Container.DataItem %>" runat="server" />
and this control use Eval() like this:
<li class="footer__sponsor-item carousel-block">
<a href="/sponsory/<%# Eval("PathInfo")%>/">
<img src="<%# Eval("Image")%>" style="width: 198px; height: 148px;"/>
</a>
</li>
And on the page i use some other control that sends postback (submit button).
The problem that after reload page there is the same html with all rendered controls, but without results of Eval() function
html before postback:
<li class="footer__sponsor-item carousel-block">
<a href="/sponsory/rossijskaja-futbolnaja-premier-liga/">
<img src="/img/Sponsors/rfpl.png" style="width: 198px; height: 148px;">
</a>
</li>
html after postback:
<li class="footer__sponsor-item carousel-block">
<a href="/sponsory//">
<img src="" style="width: 198px; height: 148px;">
</a>
</li>
How can i fix this problem?
Can i save results of Eval() with other html or can i re-render it?
UPD: Data for controls gets here:
<asp:ListView ID="ListView1" runat="server" DataSourceID="ObjectDataSource1" EnableModelValidation="true">
<LayoutTemplate>
<ul class='footer__sponsor-list'>
<li runat="server" id="itemPlaceholder" class="footer__sponsor-item" />
</ul>
</LayoutTemplate>
<ItemTemplate>
<uc4:FooterCharity ID="NewsItemUserControl1" DataSource="<%#Container.DataItem %>" runat="server" />
</ItemTemplate>
<AlternatingItemTemplate>
<uc4:FooterCharity ID="NewsItemUserControl1" DataSource="<%#Container.DataItem %>" runat="server" />
</AlternatingItemTemplate>
</asp:ListView>
...
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="LigaStavokShops.DataAccessObject.SponsorMapper" SelectMethod="GetSponsors"></asp:ObjectDataSource>
If i put breakpoint, i see that it called once - at first page load, but not after postback (render of control and GetSponsors both)
UPD2: Post data:
<asp:Button ID="SubmitVacancyFormImageButton" class="questionary___submit" CausesValidation="true" Text="Отправить анкету" runat="server" OnClick="SubmitVacancyFormImageButton_Click" />
Ok, my solve of problem is to call ListView.DataBind on page load:
<body>
<%= ListView1.DataReBind()%>
and extension class is:
public static class ObjectDataSourceHelper
{
public static string DataReBind(this ListView lv)
{
lv.DataBind();
return string.Empty;
}
}