.NET Forum / ASP.NET / General / June 2007
Pb with skinID in templated columns having DataBinder.Eval
|
|
Thread rating:  |
WT - 18 May 2007 22:47 GMT Hello,
I have a usercontrol loaded in a page with a theme.
This usercontrol contains columns template with hyperlinks, with skinID.
The columns are not displayed, seems thta there is some not traceable exception triggered and the all binding is stopped.
But this same named skinid is working for hyperlinks outside templates.
Is it a knwn problem ?
Thanks for help.
CS
Here is a sample of my code:
<asp:datagrid id="myDataGrid" runat="server" width="100%" AutoGenerateColumns="False" EnableViewState="False" AllowSorting="True"> <Columns> <asp:TemplateColumn> <ItemTemplate> <asp:HyperLink Text="<%$ Resources:ResourcesGen,EDIT %>" SkinID="editHyperLink" NavigateUrl='<%# BuildUrl(Config.ModulesPath+"/Cont/ContEdit.aspx",PageNum,"ItemNum=" + DataBinder.Eval(Container.DataItem,"ItemNum"))%>' Visible='<%# IsEditable %>' runat="server" /> </ItemTemplate> </asp:TemplateColumn>
WT - 19 May 2007 08:57 GMT More on this subject, stillno solution: on the first display ( PostBack false) the datagridrows are not display, but on the postback due to a change in the sort column, miracle ! everything is displayed ! In complement I add that viewstate is off for the Grid and that in the Page_Load event (set with a delegate in OnInit, and autoevenetwireup=false) is always binding the datagrid from the DB. Onlychange is thta the sort event generates a seconjd binding ? Should I bind twice when postback==false ?
I can't ask my users to do a postback :) ? What could be the reason ?
Thanks for help.
> Hello, > [quoted text clipped - 27 lines] > </ItemTemplate> > </asp:TemplateColumn> Walter Wang [MSFT] - 21 May 2007 04:19 GMT Hi CS,
For such issue, I hope you understand that without complete reproducible code or project, there's really not much I can do here to point out the root cause. Therefore, would you please post more complete code here for reference? Thank you.
Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WT - 22 May 2007 12:35 GMT Here is a small sample of a user control containing a datalist with templated items, codebehind follow., and skin file When the skinid is present, nothing is displayed, when removed, it is Ok. <%@ Control language="c#" AutoEventWireup="false" Inherits="FAQs" Codebehind="FAQs.ascx.cs" %>
<%@ Import Namespace="Addon.Core" %>
<%@ Import Namespace="Addon.Settings" %>
<asp:datalist ID="myDataList" runat="server">
<SelectedItemStyle BackColor="Gainsboro"></SelectedItemStyle>
<ItemTemplate>
<asp:HyperLink ID=HyperlinkItem Text="<%$ Resources:ResourcesWTCRM,EDIT %>" runat="server" NavigateUrl='<%# BuildUrl("/FAQsEdit.aspx","ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") )%>' Visible="<%# IsEditable %>" />
<SPAN class="normalBold"><asp:Literal text="<%$ Resources:ResourcesWTCRM,FAQ_Q %>" ID="Literal3" runat="server"></asp:Literal>: </SPAN>
<asp:LinkButton ID=LinkbuttonItem runat="server" CausesValidation="False" CommandName="select" Text='<%# DataBinder.Eval(Container.DataItem, "Question") %>' title='<%# DataBinder.Eval(Container.DataItem, "CreatedDate") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:datalist>
/// <summary>
-----------------------------------------------------------------------------------------------
/// IBS Portal FAQ module
/// </summary>
public partial class FAQs : UserControl
{
protected void Page_Load(object sender, System.EventArgs e){ BindData();}
private void BindData(){ FAQsDB questions = new FAQsDB(); try{ myDataList.DataSource = questions.GetFAQsGlobalized(ModuleID); myDataList.DataBind(); } catch(Exception ex) { System.Diagnostics.Trace.WriteLineIf(ModuleTraceSwitch.Sw.TraceError,string.Format("FAQs BindData ex : {0}",ex)); } }
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new EventHandler(Page_Load);
}
#endregion
-------------------- named skin in skin file <asp:HyperLink SkinId="editHyperLink" ImageUrl="img/WT_Edit.gif" runat="server" />
CS
> Hi CS, > [quoted text clipped - 14 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. WT - 22 May 2007 13:07 GMT Sorry I sent the version Ok, just replace the hyperlink with same id by <asp:HyperLink ID=HyperlinkItem SkinID="editHyperLink" Text="<%$ Resources:ResourcesWTCRM,EDIT %>" .../>
> Here is a small sample of a user control containing a datalist with > templated items, codebehind follow., and skin file [quoted text clipped - 114 lines] >> This posting is provided "AS IS" with no warranties, and confers no >> rights. Walter Wang [MSFT] - 23 May 2007 03:10 GMT Hi CS,
I can see your BindData has a try/catch block, check if there's any exception when first loaded.
Here's my test code that works fine on my side:
<%@ Import namespace="System.Data"%> <%@ Control Language="C#" ClassName="WebUserControl" %>
<script runat="server"> private string BuildUrl(string url, string qs) { return url + "?" + qs; } private bool IsEditable { get { return true; } }
protected void Page_Load(object sender, EventArgs e) { myDataList.DataSource = GetDataTable(); myDataList.DataBind(); } DataTable GetDataTable() { DataTable dt = new DataTable(); dt.Columns.Add("ItemID", typeof(int)); dt.Columns.Add("Question"); dt.Columns.Add("CreatedDate", typeof(DateTime));
for (int i = 0; i < 10; i++) { dt.Rows.Add(i, "question " + i, DateTime.Now); } return dt; }
</script>
<asp:DataList ID="myDataList" runat="server"> <SelectedItemStyle BackColor="Gainsboro"></SelectedItemStyle> <ItemTemplate> <asp:HyperLink SkinID="editHyperLink" ID="HyperlinkItem" Text="Edit" runat="server" NavigateUrl='<%# BuildUrl("/FAQsEdit.aspx","ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") )%>' Visible="<%# IsEditable %>" /> <span class="normalBold"> <asp:Literal Text="FAQ" ID="Literal3" runat="server"></asp:Literal>: </span> <asp:LinkButton ID="LinkbuttonItem" runat="server" CausesValidation="False" CommandName="select" Text='<%# DataBinder.Eval(Container.DataItem, "Question") %>' title='<%# DataBinder.Eval(Container.DataItem, "CreatedDate") %>'>
</asp:LinkButton> </ItemTemplate> </asp:DataList>
Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 28 May 2007 01:00 GMT Hi CS,
Please feel free to let me know if there's anything else I can help.
Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WT - 28 May 2007 09:41 GMT Hi Walter,
I still have the problem, but I amshort in time and must freeze it for 1 week. Anyway thanks for help. CS
> Hi CS, > [quoted text clipped - 11 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. WT - 18 Jun 2007 11:35 GMT Hello Walter,
We are back on this problem, we have found a workaround replacing the hyperlink with an ImageButton: everything works.
But for mind peace I would appreciate to understand where is the pb with hyperlink.
Thnaks for help CS
> Hi CS, > [quoted text clipped - 11 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. Walter Wang [MSFT] - 19 Jun 2007 08:12 GMT Hi CS,
Thanks for the update. Do you have a reproducible project to show the problem of the ImageButton? Thanks.
Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WT - 19 Jun 2007 09:31 GMT Thanks for answer.
I will ask for a small sample. It's difficult because we use a huge library which contains all logic with custom controls, DB access, UI, etc...
We have also noticed that inserting a div around the hyperlink drives it to run normally ?????? In fact problem seems to be in the usage of SkinID inside the hyperlink when in a datalist item.
Without the div, hyperlink is not rendered totally we only get the <a with the href='...' then nothing more: the </a> is missing and the <img> normally rendered inside with a path to the image specified in the skinid is not there. When the div is there everything is rendered correctly ????
CS
Any idea ?
CS
> Hi CS, > [quoted text clipped - 12 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. Walter Wang [MSFT] - 20 Jun 2007 03:50 GMT Hi CS,
I think we can use some mock data to test the skin behavior.
Sorry I cannot tell exactly what might be wrong at current moment without full code listing.
Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
WT - 20 Jun 2007 07:10 GMT Hello Walter,
Adding the virtual Render method in our code, with a try-catch around base.Render we get an exception with:
Cannot use a leading .. to exit above the top directory. at System.Web.Util.UrlPath.ReduceVirtualPath(String path) at System.Web.Util.UrlPath.Reduce(String path) at System.Web.Util.UrlPath.Combine(String appPath, String basepath, String relative) at System.Web.UI.Control.ResolveClientUrl(String relativeUrl) at System.Web.UI.WebControls.Image.AddAttributesToRender(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.WebControls.HyperLink.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) at System.Web.UI.WebControls.BaseDataList.Render(HtmlTextWriter writer) at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) at System.Web.UI.Control.Render(HtmlTextWriter writer)
This seems to be generated by the skinId, when the hyperlink try to add its image in the anchor. I still dont understand why, and why when adding a div around this, all seems to work....I have checked, there are no reasons for 'a leading .. to exit above the top directory' in our skinid and in the current server executing path ?????,
And I don't understand why the exception is not sent to our Application Error Handler in global.asax, under normal conditions all our exceptions catching are traced and rethrow to reach global handler. And I get no trace ???? the Page.render continue its work, missing some parts of the rendering (no closing </a>). Is it possible that .net catches something from the sending of Render without any warning or trace?
CS
> Hi CS, > [quoted text clipped - 14 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. WT - 20 Jun 2007 18:42 GMT Walter, it looks like a MS bug.
In fact when we set a SkinID in an hyperlink used in a Datalist, it appeard that the path for the imageurl, comming from the skin, is set with a path like ~/App_Themes/MyTheme/MyImage.gif.
We get this using the ItemDataBound event and tracing the imageurl for the Hyperlink.
Until now this is not a problem, but it appears that during Render, the private methods System.Web.UI.Control.ResolveClientUrl(String relativeUrl) expecting a relative url, transforms this in ../../App_Themes/MyTheme/MyImage.gif - this could be normal as the usercontrol being rendered is in an url 2 levels under the web site path-
then System.Web.Util.UrlPath.ReduceVirtualPath(String path) discovers that we are trying to get beyond the site root url and throw an exception and the code for hyperlink is not rendered.
So we transformed the imageurl set from the skin, removed the ~ and Render runs normally.
Should we have to do this everytime, what could be the reason for this ?
ReduceVirtualPath seeems to be failing in some special conditions ???
Thanks for help.
CS
> Hi CS, > [quoted text clipped - 14 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. Walter Wang [MSFT] - 21 Jun 2007 09:19 GMT Hi CS,
Things are a little complicated, could you please put up a reproducible project and send it to me? My email address is in my signature below. Thank you very much for your effort.
Regards, Walter Wang (wawang@online.microsoft.com, remove 'online.') Microsoft Online Community Support
================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|