So, I'm new to ASP.NET and website development in general. I've run into a problem using data binding to an XML file to build a site map for an ASP.NET application. Here's the first portion of the sitemap:
<Privo>
<child display="Current Projects">
<child display="Amifostin">
<child display="Experiments">
<leaf>HTT</leaf>
<leaf>MTT</leaf>
<leaf>HPLC</leaf>
<leaf>UV-Spec</leaf>
</child>
And the data binding from the site.master file:
<DataBindings>
<asp:TreeNodeBinding DataMember="child" TextField="display" />
<asp:TreeNodeBinding DataMember="leaf" TextField="#InnerText" />
</DataBindings>
What'd I'd like to do it something like this:
<leaf url="ExperimentsView.aspx/HTT">HTT<leaf>
and
<asp:TreeNodeBinding DataMember="leaf" TextField="#InnnerText" NavigateUrl="url"/>
BUT, here's the problem: when I try to bind the NavigateUrl, the only thing I can do is bind a type of node to a url - meaning, every leaf will link the the same url. Is there a way to bind a field of the leaf nodes to a (unique) url, or will I have to make different DataMembers for each unique url?
Note: yes, I know about Web.sitemap. That's what I was using when the project lead told me that he wants to use XML data binding.
You will need to use the NavigateUrlField property to do this (see http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treenodebinding.navigateurlfield.aspx)
Related
Suppose this scenario. On my Default.aspx, I insert a context (WebForms), called MyContext.ascx, that load an image. So the path would be :
<img src="/images/hello.gif" />
Well. Now, I'd like to insert the same context on another .aspx page, that is in another forlder, such as /myfolder/MyPage.aspx
Than, the path of the image now should be :
<img src="../images/hello.gif" />
How you can see, I can't manage two different path for the same context. So, is there a way (symbol) to call the virtual-path of my application? Without using my own function as
<img src="<%=MyUtilities.GiveVirtualPath%>/images/hello.gif" />
which is boring. Who know?
Put your images in the root of your web-site (and inside a resources/styles/themes folder).
You can use the tilde ~ to indicate the root of your site. All your pages will refer to that. If you're using server side controls you do not even need to use the ResolvePath() method (in your example you should use it, if for example you wrote asp:image ImageUrl="" you do not need to. From MSDN.
I am new to asp.net but Master Pages seem to do what I need - allow me to configure different templates/presentations/styles in runtime, so my app may take on a different look and feel by selecting a different Master Page. Each Master Page sits in its own folder with a set of images tailored for that "template" - I then want, in content pages, to reference various images sitting in the folder of the currently selected Master Page, for example the navigation buttons in a DataPager:
<asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1"
PageSize="25">
<Fields>
<asp:NextPreviousPagerField ButtonType="Image" ShowFirstPageButton="True"
ShowNextPageButton="False"
FirstPageImageUrl="<<Current Master Root>>/img/action-first.png"
PreviousPageImageUrl="<<Current Master Root>>/img/action-prev.png" />
<asp:NumericPagerField ButtonCount="10" NextPageText=">>"
PreviousPageText="<<" />
<asp:NextPreviousPagerField ButtonType="Image" ShowLastPageButton="True"
ShowPreviousPageButton="False"
LastPageImageUrl="<<Current Master Root>>/img/action-last.png"
NextPageImageUrl="<<Current Master Root>>/img/action-next.png" />
</Fields>
</asp:DataPager>
TEST: "<%= System.IO.Path.GetDirectoryName(MasterPageFile) %>"
(this does not work if we try to use it inside the DataPager?)
Is there a proper way to be doing this, like the tilda ~ character is used to get to the application root folder? Setting this in code is also proving to be tedious, especially for things like DataPager where the properties are nested in dynamic lists of sub controls (For example I do not know how to set the property DataPager1.Fields[0].NextPreviousPagerField.FirstPageImageUrl in code).
I have found trying to do this with Themes requires more coding than I started with because I have to include the entire control definition in the skin file, not just the image url properties, and then I have to duplicate that code in every single theme/skin. If I happen to want a DataPager with a different configuration of buttons and/or numeric fields then I have to duplicate those variations in every skin file also. If I make a change at a later date I will have to remember to make that change in all skins also - seriously defeating the purpose of separating the code from the skin.
My application runs multiple projects, and each project may select its own template. For the entire application I want to say: if the current project uses TemplateX then use images from folder /TemplateX/img/, if TemplateY is seletected then use images from /TemplateY/img/. As you know CSS cannot always be relied upon to determine what image to use where, so we have to be able to put the image reference directly in the HTML output.
In the custom ISAPI DLL web system I developed I simply use a substitution string like "[#HTML.Template]/img/prev.png" to stick the template folder in front of the image URL. Is there perhaps a way I can hook a custom .aspx preprocessor to manually substitute all ocurrences of, as in the example above, "<< Current Master Root >>" with the currently selected folder?
try use smething like this
var path = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;
I want to attach the xml file data to the menu through the XmlDataSource.
I did that but it display from root node. How to do if do not want root node menu. & all the sub menus in same level. eg File, Edit, View etc. Because not to do so then we get unnecessary one extra level for root level menu.
Regards,
Girish
Use the XmlDataSource.XPath property to specify the entry point to the data you want to show for example
XmlDataSource.XPath = "xml/submenus";
Modify the XPath to point to the correct tags in the xml file.
ASPX:
XPATH="ROOT/TARGET"
XML:
<ROOT>
<TARGET TEXT="STARTS HERE">
<DATA TEXT="OTHER DATA HERE" />
</TARGET>
</ROOT>
In my custom aspx page in WSS I am using a DataFormWebPart with an XSL file to render some data. In order to pass values to the XSL I use parameter bindings. Specifically, I need to pass in the server host URL like this:
<ParameterBinding
Name="HttpHost"
Location="CAMLVariable"
DefaultValue="http://hardcoded.com" />
This works fine, but the next thing I want to do is to get the host name dynamically. So figuring out how to get that from SharePoint I added the following binding:
<ParameterBinding
Name="HttpHost"
Location="CAMLVariable"
DefaultValue='<%# SPContext.Current.Site.Url.Replace
(SPContext.Current.Site.ServerRelativeUrl, "") %>' />
Now to the problem. The code works as expected if used some other place in the page, but with the above code SharePoint reports:
Web Part Error: The 'ParameterBindings' property of 'WebPartPages:DataFormWebPart'
does not allow child objects.
Anyone have a take on this?
I have enabled server side code according to SharePoint 2007: using ASP.NET server side code in your pages
After trying various methods of manipulating the ParameterBindings property without success I thought of how I could get the dynamic value in there using the Location attribute.
The ParameterBinding Location attribute refers to where to fetch the value from. Articles like this hints of the "Control()" option. So changing the parameter binding to:
<ParameterBinding
Name="HttpHost"
Location="Control(MyHttpHost, Text)"
DefaultValue="" />
and adding the following code to my page:
<asp:TextBox ID="MyHttpHost" runat="server" Visible="false" />
<script runat="server">
protected void Page_Load()
{
MyHttpHost.Text =
SPContext.Current.Site.Url.Replace(SPContext.Current.Site.ServerRelativeUrl, "");
}
</script>
...actually did the trick!
To get to the parameter values from within the accompanying XSL file I put param elements in the root element. The param name attribute must match that of the ParameterBinding:
<xsl:stylesheet ...>
...
<xsl:param name="HttpHost"/>
The parameter can then be referenced as any other XSL variable.
I'm looking at an ASP.NET application which makes heavy use of meta:resourcekey which seem to be connected to the resx files.
This is an area that seeems to have completely passed me by. Does anyone have any guidance on the benefits and purpose of this approach and best practices?
The meta:resourcekey syntax allows you use declarative syntax for Implicit Resource expressions. This is used when localizing a site for international use. As the Quickstarts (linked below) explain, these kind of expressions are linked to .resx files located in the App_LocalResources folder.
The benefit of this kind of expression is that it can use multiple properties for a single control which are defined in the .resx file instead of the ASPX itself.
For instance, take the label below:
<asp:Label ID="myLabel" runat="server" Text="This text is localizable" meta:resourcekey="myLabelResource1">
</asp:Label>
The resx file for this page could contain data for multiple properties attached to the label such as:
<data name="myLabelResource1.Font-Name">
<value xml:space="preserve">Default Font name</value>
</data>
<data name="myLabelResource1.Text">
<value xml:space="preserve">Text in default language.</value>
</data>
<data name="myLabelResource1.ToolTip">
<value>Tooltip in default language.</value>
</data>
The ASP.NET quickstarts provide a great primer if you want to understand the concept.