Pb with skinID in templated columns having DataBinder.Eval

W

WT

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>
 
W

WT

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.
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
W

WT

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>:&nbsp;</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
 
W

WT

Sorry I sent the version Ok, just replace the hyperlink with same id by
<asp:HyperLink ID=HyperlinkItem SkinID="editHyperLink" Text="<%$
Resources:ResourcesWTCRM,EDIT %>" .../>
 
W

Walter Wang [MSFT]

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>:&nbsp;</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 ([email protected], 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.
 
W

Walter Wang [MSFT]

Hi CS,

Please feel free to let me know if there's anything else I can help.

Regards,
Walter Wang ([email protected], 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.
 
W

WT

Hi Walter,

I still have the problem, but I amshort in time and must freeze it for 1
week.
Anyway thanks for help.
CS
 
W

WT

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
 
W

Walter Wang [MSFT]

Hi CS,

Thanks for the update. Do you have a reproducible project to show the
problem of the ImageButton? Thanks.


Regards,
Walter Wang ([email protected], 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.
 
W

WT

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 
W

WT

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
 
W

WT

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
 
W

Walter Wang [MSFT]

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 ([email protected], 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.
 

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,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top