J'ai un UpdatePanel qui contient un gridview. Sur chacune des lignes de la grille, à l'intérieur de la grille, j'ai un bouton Twitter et FaceBook.
La grille s'affiche bien avec les boutons au chargement de la page, mais dès qu'un postback partiel est effectué sur le panneau de mise à jour, les boutons Twitter et FaceBook ne s'affichent pas.
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!-- search controls.... -->
<asp:ImageButton ID="btnSearch" ImageUrl="~/img/button-search.gif" runat="server" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True"
BorderStyle="None" Font-Size="Small" GridLines="None" AllowPaging="True" ShowFooter="True"
Width="100%" OnPageIndexChanging="GridView1_PageIndexChanging">
<RowStyle CssClass="row1" />
<AlternatingRowStyle CssClass="row2" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
...
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="ltlTwitter" runat="server" Text='<%# GetTwitterURL(Eval("ID"), Eval("SomeText")) %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Literal ID="ltlFacebook" runat="server" Text='<%# GetFacebookURL(Eval("ID")) %>'></asp:Literal>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" Visible="False" />
</Columns>
<EmptyDataTemplate>
<strong>There are no offers for this search criteria.</strong>
</EmptyDataTemplate>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnSearch" />
</Triggers>
</asp:UpdatePanel>
C# pertinent :
public static string GetTwitterURL(object ID, object text)
{
...
StringBuilder sb = new StringBuilder();
sb.Append("<div>");
sb.Append("<a href=\"http://twitter.com/share\" " +
"class=\"twitter-share-button\" ");
sb.AppendFormat("data-url=\"{0}?ID={1}\" ", obj.Property, oID.ToString());
sb.Append("data-via=\"xxx\" ");
sb.AppendFormat("data-text=\"{0}\"", xxx);
sb.Append("data-count=\"none\">Tweet</a>");
sb.Append("</div>");
return sb.ToString();
}
public static string GetFacebookURL(object OfferID)
{
...
return string.Format("<fb:like href=\"{0}?ID={1}\" " +
"send=\"false\" layout=\"button_count\" show_faces=\"false\" " +
"action=\"like\" font=\"tahoma\"></fb:like>", obj.Property, someInt);
}
De plus, la page en question est une page enfant d'une page maître.
Voici le code-behind supplémentaire :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindOffersGrid(true);
}
}
public List<Offer> CurrentOffersDataSet
{
get
{
object o = ViewState["CurrentOfferDataSet"];
return (o == null ? new List<Offer>() : (List<Offer>)o);
}
set
{
ViewState["CurrentOfferDataSet"] = value;
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = this.CurrentOffersDataSet;
GridView1.DataBind();
}
private void BindOffersGrid(bool ApplyRandomSort)
{
List<Offer> lstOffers = Offers.GetAllBySearchCriteria(
Convert.ToInt32(ddlOfferCounty.SelectedValue),
Convert.ToInt32(ddlOfferTypes.SelectedValue),
Convert.ToDateTime(ddlOfferDate.SelectedValue), -1, true);
...
//Some filtering of the dataset with Linq
...
GridView1.DataSourceID = string.Empty;
this.CurrentOffersDataSet = lstFilteredOffers.
OrderByDescending(a => a.IsExclusive).
ThenBy(a => Guid.NewGuid()).
ToList();
GridView1.DataSource = this.CurrentOffersDataSet;
GridView1.DataBind();
}