I have a custom UserControl (inherits System.Web.UI.UserControl) with this property, which should be set to a URL on the site that you want to link to:
[DefaultValue("~/NewsItem.aspx"), UrlProperty("*.aspx")]
public string InternalItemViewUrl
{
get { return _internalItemViewUrl; }
set { _internalItemViewUrl = value; }
}
The control will present the URL picker drop-down correctly, but if you select a URL from the list, it does not change it to a site-relative "~/foo.aspx" link, like HyperLink does, but instead only gets "foo.aspx" which does not work (the control is in /controls and the page obviously is not). If you scroll all the way down and use "Pick URL..." which opens the full pop-up window, a page selected in that dialog does get converted to "~/foo.aspx"
Am I missing something obvious here to make this work?
Check out the attributes on the HyperLink, especially the [Editor] attribute.
[DefaultValue(""),
WebSysDescription("HyperLink_NavigateUrl"),
UrlProperty, Bindable(true), WebCategory("Navigation"),
Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
It doesn't matter where the control is, the url is relative the page the control is placed on.
So if the control is placed on page "foo.aspx" and it references a page "foo2.aspx" (that is in the same directory as "foo.aspx"), then just haveing "foo2.aspx" in the control's url property will work.
Related
Using Magnolia CMS, I am trying to make a property inherit through all child pages.
The property gets set from a base page dialog.
Essentially its just a checkbox that toggles a show/hide Boolean that gets tested in the main page template (which child pages also use).
The dialog control component 'hideHeader' has this structure:
::hideHeader
.buttonLabel: Hide
.class: info.magnolia.ui.form.field.definition.CheckboxFieldDefinition;
.defaultValue: true;
.i18n: true;
.inheritable: true;
.label: hide;
.type: Boolean;
Which is added to the base page dialog.
I access the property in the template like:
[#assign hideHeader = false /]
[#if content.hideHeader?? && content.hideHeader?has_content ]
[#assign hideHeader = content.hideHeader /]
[/#if]
I cant get it to work in the child pages. It doesn't pick up on the set value from the dialog, just the default 'false' value.
What am I missing?
In order to inherit property from anywhere up in the hierarchy of pages, you need to use cmsfn.inheritProperty(content, "your-prop-name").
Using only stkfn.siteRoot(content) as suggested above, will return you root node of the site, so if value was overridden anywhere in the hierarchy you would not see that.
HTH,
Jan
so after suffering from 'code' blindness, I realised to implement the behaviour I wanted I needed to get the property using:
stkfn.siteRoot(content)
this now enables all sub pages to receive the parent pages properties.
Instead of all code above you can just use:
[#assign hideHeader = content.hideHeader!false]
To inherit property you have function in TemplatingFunctions
public Property inheritProperty(Node content, String relPath)
in freemarker you should do something like:
cmsfn.inheritProperty(content, "hideHeader ");
I have a master page with a user control added. The user control has properties, price and exchange rate.
I can get the control from a normal page by using master.findcontrol but it sees it as just a normal user control, so i cant get access to the controls properties, price or exchange rates.
Is there a way to solve this?
Thanks to all who view
Why not expose your custom control as a property of the masterpage. Then you can reference it like:
Master.YourCustomControl.YourCustomProperty
You have to cast the control to your custom control in order to access the properties of your custom control,
var control = (YourCustomControl)Master.FindControl("YourCustomControl");
I guess you have not exposed any properties for your custom control, Try the following,
public partial class YourControl: System.Web.UI.UserControl
{
public string textboxtext{
get { return tb_Textbox.Text ;}
set { tb_Texbox.Text = value; }
}
}
Once you create properties for all the customizable properties for your custom control, you then can access or modify them.
I have a simple master page (master.aspx), which has 3 link buttons namely HomeLBTn-which redirects the users to home.aspx, LoginLBtn-to login.aspx, RegisterLBtn-to Register.aspx
Every page in my project inherits the master page. And home.aspx also inherits the master.aspx, but i don't want the home.aspx to inherit the HomeLBtn, I want it to inherit the remaining 2 LBtn's, but not the HomeLBtn. How can i incorporate this condition into Home.aspx
Please help me
Thanks in anticipation
One way would be to find the control in the MasterPage and set its visibility to false:
Page.Master.FindControl("HomeLBtn").Visible = False
This would be done in the Page_Load (or some other lifecycle event) on the page that shouldn't show the Home button.
In master.aspx, define Register and Login link buttons, and a content placeholder for where the Home button would go. Then have Home.aspx inherit master.aspx. Then create a 2nd master page (master2.aspx) that inherits from master.aspx. In master2, add the Home link button in the content placeholder, and have your other pages inherit from master2.
You can do something like this in the master page ( Check what the child page is )
//If the child page is viewing an order then disable the new request button
if (this.ContentPlaceHolder1.Page is OrderView)
{
base.RemoveMenuItem("New Request", mnuSettings);
}
Note: base.RemoveMenuItem is a method of my base page
http://wraithnath.blogspot.com/2010/09/how-to-hide-show-controls-on-master.html
Another option would be to add a property to the child page and master page and use session data to hide and show buttons.
eg. in Child Page:
protected MyCustomMasterPage CustomMasterPage
{
get
{
return this.Master as MyCustomMasterPage;
}
}
In your master page you could have a session variable you can set to hide and show the buttons
public bool HomeVisible
{
get
{
return (bool) Session["HomeVisible"];
}
set
{
Session["HomeVisible"] = value;
}
}
You would then check the HomeVisible property when loading the master page to show / hide the button. You can then set this from the child page.
this.MyCustomMasterPage.HomeVisible = false;
Maybe not the best ways but they work
I currently use SiteMapPath to generate a breadcrumb for my ASP.net 3.5 (vb.net) pages and it works great.
Now I am trying to figure out how I might be able to use the same control to build a dynamic page title (in the tag). I want a reverse path listed, but the SiteMapPath control includes links and bunch of styling spans. Is there any way to remove all of that, and just get a plain path with separators?
For example, Let's say we are on the "Press Releases" page inside of the "About" section of my site.
The breadcrumb shows up as:
Home > About > Press Releases
I want to have the page title be:
Press Releases - About - Company Name
So I need it to reverse the order, drop all spans, links and styling (since this is inside the tag) and drop the root node "Home" and then add the company name to the end. Since my menu nav and breadrumbs are all driven from the sitemap file, I thought it would make sense to try to make the title do the same.
Any thoughts? Thanks.
The best way to achieve your desired output is to ignore the SitePath control, and instead use the SiteMap's SiteMapNode's collection. The server parses the web.sitemap into a collection of SiteMapNodes and wires up the SiteMap.CurrentNode by finding a node that matches the current page's URL. Each SiteMapNode has a ParentNode property. Here is the reference page on MSDN.
So, all you need to do is check if the CurrentNode has a parent, if it does you add the ParentNode's title to the CurrentNode's title and keep going until you reach the RootNode (where you substitute your company name for the root node's title).
Below is a quick solution; it could go in the MasterPage if you are using one. I'm not sure your language, but this should be easy to rewrite in VB.Net. I gave it a simple test and it seemed to work.
You can customize the characters that separate the page titles.
protected void Page_Load(object sender, EventArgs e)
{
Page.Title = SiteMapTitle(SiteMap.CurrentNode, "", " - ");
}
private string GetNodeTitle(SiteMapNode oNode)
{
if (oNode == SiteMap.RootNode)
return "Company Name";
else
return oNode.Title;
}
private string SiteMapTitle(SiteMapNode oNode, string szTitle, string szItemSeparator)
{
if (szTitle != string.Empty)
szTitle = szTitle + szItemSeparator + GetNodeTitle(oNode);
else
szTitle = GetNodeTitle(oNode);
if (oNode.ParentNode != null)
szTitle = SiteMapTitle(oNode.ParentNode, szTitle, szItemSeparator);
return szTitle;
}
Hope that helps...
I am making a custom ImageButton Control which has the option to show button clicked effect by adding onmouseup and onmousedown javascript code to change image URL. I have constructed the control and it has a ClickImageUrl to set the URL of image to be shown when button is clicked..
i wanted to know is there any way i can add a Select URL dialog box for my control just like the Dialog box for ImageUrl. is it even possible??? and if so how would i go about doing it...??
any help will be much appreciated.
EDIT: based on the answer by Arther i am able to show a Select Image URL diaolog box when i use it to set ClickImageUrl it shows a designer error as :
Error Rendering Control
An unhandled exception has occured
'~/images/7.jpg' cannot be set on property 'ClickImageUrl'
is it conflicting with the ImageUrl ???
If your talking about the VS Designer, then you have to decorate your Property with these Attributes:
public class CustomImageButton : System.Web.UI.WebControls.ImageButton
{
[Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[UrlProperty]
public string ClickImageUrl { get; set; }
}