Add A Custom / Namespaced XHTML Attribute To A Web Control Declaratively?
Aug 24, 2010
Normally, unknown attributes of a webcontrol are passed through to to the rendered element in the browser. So the following works.
<asp:label runat="server" Text="Label Text" helpId="101" />
However, if you use a namespaced attribute like the following
<asp:label runat="server" Text="Label Text" myNs:helpId="101" /></div>
The attribute is not rendered to the client, even when the custom namespace is declared in the html element like: <html xmlns= [URL] Does anyone know of a way to get this to render to the client, without having to use a custom control. A module or other globally "pluggable" solution would be acceptable.
View 1 Replies
Similar Messages:
May 21, 2010
I've been working on this project for a few days now, and have been unable to resolve the issue of getting intellisense support for my custom-defined inner properties for a user control (ascx, mind you). I have seen the solution to this (using server controls, .cs mind you) many times. Spelled out in this article very well. Everything works for me while using ascx controls except intellisense. Here's the outline of my code:
[PersistChildren(true)]
[ParseChildren(typeof(BreadCrumbItem))]
[ControlBuilder(typeof(BreadCrumbItem))]
public partial class styledcontrols_buttons_BreadCrumb : System.Web.UI.UserControl
{
...
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public List<BreadCrumbItem> BreadCrumbItems
{
get { return _breadCrumbItems; }
set { _breadCrumbItems = value; }
}
...
protected override void AddParsedSubObject(object obj)
{
base.AddParsedSubObject(obj);
if (obj is BreadCrumbItem)
BreadCrumbItems.Add(obj as BreadCrumbItem);
}
...
public class BreadCrumbItem : ControlBuilder
{
public string Text { get; set; }
public string NavigateURL { get; set; }
public override Type GetChildControlType(string tagName, System.Collections.IDictionary attribs)
{
if (String.Compare(tagName, "BreadCrumbItem", true) == 0)
{
return typeof(BreadCrumbItem);
}
return null;
}
}
}
Here's my mark up (which works fine, just no intellisense on the child object declarations):
<%@ Register src="../styledcontrols/buttons/BreadCrumb.ascx" tagname="BreadCrumb" tagprefix="uc1" %>
...
<uc1:BreadCrumb ID="BreadCrumb1" runat="server" BreadCrumbTitleText="Current Page">
<BreadCrumbItem Text="Home Page" NavigateURL="~/test/breadcrumbtest.aspx?iwentsomewhere=1" />
<BreadCrumbItem Text="Secondary Page" NavigateURL="~/test/breadcrumbtest.aspx?iwentsomewhere=1" />
</uc1:BreadCrumb>
I think the issue lies with how the intellisense engine traverses supporting classes. All the working examples I see of this are not ascx, but Web Server Controls (cs, in a compiled assembly).
View 1 Replies
Aug 28, 2010
I am sure this question has been asked and answered; but I haven't managed to find it...
I am creating a very simple custom System.Web.UI.Control that has a few properties. I can define in my ASPX page the following tag and everything is happy:
<ns:MyControl runat="server" MyProperty="Value" />
However, if I want to have one or more "child" properties, like so:
<ns:MyControl runat="server" MyProperty="Value">
<Element AnotherProperty="AnotherValue1" />
<Element AnotherProperty="AnotherValue2" />
</ns:MyControl>
what I need to do to make the XHTML validate. I always have
Content is not allowed between the opening and closing tag of element 'XXX'
Element 'XXX' is not supported
The name contains uppercase characters, which is not allowed
The code actually runs as expected, but I haven't manged to find a good example on how to do this correctly so that everything validates. In terms of implementation of the Custom Control, I just have all properties stubbed out at the moment, and looks something like:
[ParseChildren(true)]
[PersistChildren(false)]
public class MyControl : Control[code]....
Ultimately, Element is intended to build up a collection of Elements. Any insight on how to do this properly and have the XHTML validate
View 2 Replies
May 13, 2010
[VS 2010 RC1, .NET 4.0, VB.NET]
I'm working with a simple UserControl someone at my company created. It's basically just a DropDownList with a RequiredFieldValidator and some added properties (such as "Required", which controls the CSS styling of the DropDownList and whether the RequiredFieldValidator is Enabled or not).
Here is an example of the UserControl usage where a SqlDataSource is used to populate the ListItemCollection. I'm trying to specify an intial ListItem below (and would like the ability to add multilple ListItems if necessary) but can't seem to get this to work...
[Code]....
My code-behind looks as follows:
[Code]....
I've found several posts related to this but cannot seem to get the declarative ListItem to be added to the DropDownList.
I understand that using a WebControl is another option, but I'd like to learn how to get this method to work if possible.
View 5 Replies
Jan 17, 2011
How do I do something like the following:
[Code]....
View 2 Replies
Feb 24, 2011
If certain attributes on built-in ASP.NET controls aren't specified, then an exception will be thrown.
How do I do this on my custom user/server control?
View 2 Replies
Jul 30, 2010
[Code]....
I am having a problem setting the SystemObjectRecordID attribute of my custom control inside a repeater. Currently, the value winds up as zero in the database. Things I have checked:
1) The datatype of the DB column (bigint) and the datatype of AlertId (long) and the datatype of the getter/setter SystemObjectRecordID variable (long) match.
2) If I set '<%# ((Alert)Container.DataItem).AlertId %>' to the Text attribute of a label I get the expected results. So, it has something to do with my custom control and specifically how data isbound to the SystemObjectRecordID attribute.
Now, going to the server, below is what I have for databinding (The page is Default.aspx.cs and the namespace is Company.ProjectWeb.Profiles):
[Code]....
Currently I am trying to pass the value received from a literal (because I know that the values are received as expected here) to the SystemObjectRecordId object. Still isn't working. I am still getting a value of zero when I set a breakpoint and look at the value of SystemObjectRecordId in the codebehind of my control:
[Code]....
View 10 Replies
Jan 26, 2010
I have a custom control that I declare like:
<hello:someControl id="asdf" />
Now I need to access a config setting in the web.config's appsetting and give access to it to the control.
I want to pass this value using the attribute.
How can I do this?
View 1 Replies
Jan 11, 2010
I've noticed that on aspx page IntelliSense doesn't display the Style property of a web control, even thought the control does have a Style property. Does that mean we shouldn't declaratively set the Style property:
<asp:TextBox ID="UserName" Style="color:Green; padding:0px; margin:0px;" runat="server"></asp:TextBox>
View 2 Replies
Aug 19, 2010
I have a User Control (ascx) and a property which a want to display in my categories tab in Visual Studio in the category named "Styles".
[Code]....
And here is the problem: Actually I do not need a get, because I only have to set the property (write only property). But when I omit the get, the property is displayed in the "Misc" category in the categories tab in Visual Studio. Only when I code the get as well, then the property is displayed correctly in the "Styles" category in the categories tab in Visual Studio.
Does anybody know why? How can I display the category correctly only with set?
View 2 Replies
Oct 29, 2010
I'm looking for an ASP.NET control that renders a tree structure, very much like the ASP.NET TreeView control, but filling the following requirements:
Dont uses tables for rendering tree structure.
Markup Adhering to valid XHTML 1.0 Strict.
Works with AND without javascript.
Also, if the control is licensed under a MIT och GPL licens that would be great, but commercial controls is also of interest.
Do anyone know of any such control? If not, well, then I'll simply have to write the control myself. More fun in my own opinion, but likely more time consuming.
View 2 Replies
Feb 1, 2011
I created a simple Master Page in Visual Studio 2008:
<%@
Master
Language="VB"
CodeFile="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE
html
PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
and got green underlined 'Master' with two warning messages: 1.Validation (ASP.NET): This attribute name must be followed byan equal (=) sign and a value. If the value is in quotation marks, the quotation marks must match. 2. Validation (ASP.NET): Attribute 'Master' is not a valid attribute of element 'Control'.How I can get rid of the messages?
View 3 Replies
Mar 8, 2011
Supposing I have a user control like this <MyTag:MyWidget runat="server" /> I am wondering if I can do something like <MyTag:MyWidget runat="server" MemberHeight="400" PublicHeight="200" /> So that in MyWidget.ascx I can have <div height="<%=IsLoggedIn ? MemberHeight : PublicHeight%>"> or something like that...? Because I want the height to vary in each page that is using this widget.
View 2 Replies
Mar 2, 2010
I want to create a single custom authorization attribute to be added to controller actions that require authenticated users.
My first shot at this, so I may have it all wrong
Got 3 Roles which corresponds to 3 Areas in my application (Client app, so I'll just call them RoleOne, RoleTwo, RoleThree and AreaOne, AreaTwo, AreaThree).
Each area have similiar (to a point) views and actions, like Sign Up, Area specific home, etc.
In the attribute I want to determine the current area, controller and action. Then I just add code like:
If not logged in, and in AreaOne, go to AreaOne Signup (etc)If logged in as RoleOne, and AreaOne Home is requested, go there, but if AreaTwo Home is requested ,go to AreaTwo Signup So in my attribute class I need to determine the current area, controller and action, and see what kind of user we have logged in (if any)
Using ActionExecutingContext it seems I can determine the contoller and action method names, however I cannot find the Area name, and altered the attribute to be called like this:
[Code]....
View 4 Replies
Nov 7, 2010
I am trying to create a minimum length validation attribute which will force users to enter the specified minimum amount of characters into a textbox
public sealed class MinimumLengthAttribute : ValidationAttribute
{
public int MinLength { get; set; }
public MinimumLengthAttribute(int minLength)
{
MinLength = minLength;
}
public override bool IsValid(object value)
{
if (value == null)
{
return true;
}
string valueAsString = value as string;
return (valueAsString != null && valueAsString.Length >= MinLength);
}
}
In the constructor of the MinimumLengthAttribute I would like to set the error message as follows:
ErrorMessage = "{0} must be atleast {1} characters long"
How can I get the property's display name so that I can populate the {0} placeholder?
View 1 Replies
Jun 6, 2010
Is it possible to access a parent class from within an attribute.
For example I would like to create a DropDownListAttribute which can be applied to a property of a viewmodel class in MVC and then create a drop down list from an editor template. I am following a similar line as Kazi Manzur Rashid here.
He adds the collection of categories into viewdata and retrieves them using the key supplied to the attribute.
I would like to do something like the below,
public ExampleDropDownViewModel {
public IEnumerable<SelectListItem> Categories {get;set;}
[DropDownList("Categories")]
public int CategoryID { get;set; }
}
The attribute takes the name of the property containing the collection to bind to. I can't figure out how to access a property on the parent class of the attribute. Does anyone know how to do this?
View 2 Replies
Jan 20, 2010
I've create a custom attribute for my web pages... In the base page class I've created I'm trying to pull if that attribute has been set. Unfortunately it does not come back as part of the GetCustomAttributes function. Only if I explicitly use the typeof(myclass) to create the class. I have a feeling it's due to how asp.net classes are generated.
[Code]....
View 1 Replies
Jul 22, 2010
I have some code which is rendering some custom attributes of Hidden Control (without runat=server).
Something like,
And I have a lot of these hidden elements on my form.
When I submit the form, I am looping through a set of ids, say 1200 to 1250, so I will read controls based on that, and also hidden with Request.Form["hdn "]
Now problem is, as we know we get value attribute from form when we do Request.Form["id"] for hidden, I want to read my custom attributes from hidden element. Is there any way? Note that, I can not touch the rendering part here.
View 1 Replies
Jan 21, 2010
I have a class containing the following ConfigurationSection:
namespace DummyConsole {
class TestingComponentSettings: ConfigurationSection {
[ConfigurationProperty("waitForTimeSeconds", IsRequired=true)]
[IntegerValidator(MinValue = 1, MaxValue = 100, ExcludeRange = false)]
[Code]....
The value for the property 'waitForTimeSeconds' is not valid. The error is: The value must be inside the range 1-100.
If I change the IntegerValidator to have an ExcludeRage = true, I (obviously) get:
ConfigurationErrorsException was unhandled
The value for the property 'waitForTimeSeconds' is not valid. The error is: The value must not be in the range 1-100
If I then change the value of the property in the .config to a number higher than 100, it works.
If I change the validator to just have a MaxValue of 100 it works, but will also accept a value of -1.
Is it possible to use the IntegerValidatorAttribute with a range like this?
Edit to add
Confirmed as an issue by Microsoft.
View 1 Replies
Jun 12, 2012
To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
I got this error at time of running ma published website but only for 1page this error occurred how it can be solved.
View 1 Replies
Nov 13, 2010
I'm new to ASP.NET and MVC in particular. Now, I'm trying to understand if I can easily get values of custom attributes of submitted data. For example, When writing something like this inside a form (which works and posts and I can get the checkbox value) <%= Html.CheckBox("cb1", new { listen = "listen:6" }) %> Can I get the value of "listen" directly or do I need JS? (I know I can just use hidden fields, but I'm I'm asking anyway)
View 1 Replies
Mar 4, 2010
I have a custom authorization attribute, that basically check if the current user's role is equals to the current area name, and if not, redirect them to the signup view in that requested area. (dummy role provider at this this stage, therefor check it against the user's name at the moment)
It runs fine (IIS) but when I debug it I can see a Security Exception are being thrown by the code
The code:
[Code]....
View 2 Replies
Jan 19, 2011
I have a wep page in which there are many links with a custom attribute profileID:-
<a href="javascript:__doPostBack('M$C$CandidateSearch1$gdvSearchResult$ctl02$lnkNameAge','')" title="View Details of Saleem Khan (25)" id="M_C_CandidateSearch1_gdvSearchResult_ctl02_lnkNameAge" onclick="window.open('../Popup/ProfilePersonalInformationPopup.aspx?key=3030224&mode=view'
profileID='3030224');return false;">Saleem Khan (25)</a>
now If user type 3030224 in a textbox and press gotoLink button then i have to click that hyper link through code i.e. I have to call
onclick="window.open('../Popup/ProfilePersonalInformationPopup.aspx?key=3030224&mode=view'
for that profile ID.
Now the problem is that how can I search the page and get the <a> object with specific profileid.
View 5 Replies
Jul 22, 2010
I have some code which is rendering some custom attributes of Hidden Control (without runat=server).
Something like,
<input type='hidden' id = 'hdn1221' name = 'hdn1221' OldValue = '12' OldMode = 'A' />
And I have a lot of these hidden elements on my form.
When I submit the form, I am looping through a set of ids, say 1200 to 1250, so I will read controls based on that, and also hidden with Request.Form["hdn<Id> "]
Now problem is, as we know we get value attribute from form when we do Request.Form["id"] for hidden, I want to read my custom attributes from hidden element. Is there any way? Note that, I can not touch the rendering part here.
View 5 Replies
Oct 8, 2010
I have an ASP.NET 3.5 Site where, in some places, I am checking if the currently logged on Active Directory user is in a certain AD Security Group. In the Page_Load I'm doing something like this:
if (isInADGroup(UserGUID))
{
//proceed
}
Now I was wondering, couldn't I just create a Custom Attribute, like some of MVC's security attributes, which runs this check and cancels the execution or displays an error message?
View 1 Replies