C# - Specify A Range With The IntegerValidator Attribute On A Custom ConfigurationSection?

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


Similar Messages:

C# - Add A Textnode Instead Of An Attribute In A .NET Configurationsection?

Feb 22, 2011

I currently have a .NET custom configurationsection that looks like this:

<customSection name="My section" />

What I want is to write it as a textnode (I'm not sure if this is the correct term?) like this:

<customSection>
<name>My Section</name>
</customSection>

My current customSection class looks like this:

public class CustomSection: ConfigurationSection {
[ConfigurationProperty("name")]
public String Name {
get {
return (String)this["name"];
}
}
}

What should I do to make it a textnode?

View 1 Replies

C# - Moq ConfigurationSection?

Dec 8, 2010

my application has the following code:

public interface IConfigurationManager {
CustomSection Settings { get; }
}

[code]...

View 1 Replies

C# - Custom Attribute In A UserControl (ascx)?

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

MVC :: Bit Lost On First Custom Authorization Attribute?

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

C# - Get Property's Display Name From A Custom Attribute?

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

C# - Access Parent Class From Custom Attribute?

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

Retrieving Custom Attribute On A Webpage Class

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

C# Get Custom Attribute Of Hidden From Request.Form

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

Web Forms :: Custom Errors Tag Should Then Have Its Mode Attribute Set To Off

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

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

MVC Reading An Element's Custom Html Attribute When Submitting?

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

MVC :: Custom Authorization Attribute Throws Security Exception

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

JQuery :: Select Hyperlink In Page With A Custom Attribute?

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

Web Forms :: Get Custom Attribute Of Hidden From Request.Form?

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

C# - Custom Attribute In .NET For Page_Load / Displays An Error Message?

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

MVC :: Custom Authenticate Attribute With Constructor (Dependency) Injection?

Sep 7, 2010

I have a [BeastAuthenticate] attribute on my controller. The following code works fine but I would like to use Contructor (Dependency) Injection with Unity. The problem is that the attribute will run the contructor with no parameters. terfaces ITMSLogger and IADGroups are setup to use Dependency Injection with TMSLogger and ADGroups respectively. The following code works fine but doesn't use dependency injection for class ADGroups.

[Code]....

I tried the following but I'm getting an error ("Object reference is required...") with "this (adGroups).

[Code]....

View 2 Replies

Range Validator Failing / If Enter Value 450 In Textbox To Validate It In Range 25 To 50

Apr 30, 2010

I am facing problem using range validator.

Like in code below

[code]

If I enter value 450 in textbox to validate it in range 25 to 50 ,it won't give any error message

View 1 Replies

Range Validator - Alphabet Entered When Integer Range Checked

Sep 23, 2010

I have a Range Validator as follows. It is for restricting values between 1900 and 2070. However, it fires error when I enter a alphabet also. I want this to be fired only if the user enters integer values. How do I overcome it?

<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="txtYear"
ValidationGroup="report" ErrorMessage="EM1|Year" MaximumValue="2079" MinimumValue="1900"
SetFocusOnError="True" Display="Dynamic" Type="Integer">
<img src="../../Images/error.gif" alt="Format" />
</asp:RangeValidator>

View 1 Replies

Web Forms :: When Using A Range Validator, If The User Exceeds The Defined Range?

Jan 1, 2010

When using a range validator, if the user exceeds the defined range, How do you code it so it disables a button so the user can't continue. (without using JavaScript)

View 3 Replies

Web Forms :: Add Custom Server Side Attribute To TextBox Control?

Jan 17, 2011

How do I do something like the following:

[Code]....

View 2 Replies

How To Make An Attribute On A Custom User / Server Control Be Mandatory

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

MVC :: Runtime Sitemap Construction For Each Index() ActionMethod - Custom Attribute?

Jun 21, 2010

Recently, I wrote code that dynamically builds a menu / navbar for my site that uses Reflection upon the [Authorize(Roles="")] attribute to determine what Controllers and ActionMethods should be shown to the user. And it came out really well. See this post for the details on how I did it: [URL]

The next step that I've been thinking about is when the user clicks on the "Controller" listing, it takes the user to the Index page. (eg. [URL] ) Which is perfectly fine, but I was thinking that it would be nice to also have this Index page for each controller dynamically constructed based on the user's roles / permissions. For example, if the Index page from XYZ-Controller might look like:


XYZ-Controller Index
SomeMethod1 -- This method tweaks your widgets
SomeMethod2 -- This method unwinds your widgets, re-orders thems, and then re-winds them, but only on Tuesdays.
SomeMethod3 -- This method will delete some or all of your widgets and then you'll be sad.

I currently use Reflection to iterate thru all my Controllers and all the ActionMethods in each controller. I've been pondering the best way to store the Description of each ActionMethod. (Like, "This method tweaks your widgets.") Do I make my own Attribute called, say, Description which I would use to decorate ActionMethods with. For example it might look like this: [Description("This method tweaks your widgets")]

View 2 Replies

Forms Data Controls :: Set Attribute In Custom User Control And Keep Getting Zero?

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

MVC - Mark Multiple Fields Invalid In Custom Validation Attribute?

Mar 2, 2011

I have a form where users enter their preferred contact method. It has:

- a radio button where a user selects whether they'd like to be contact by phone or email or either

- a textbox for the user's email address

- a textbox for the user's phone number

I have validation via a custom attribute that verifies that if the user selected phone they entered a phone number, if they selected email they entered an email, etc... but it's at a class level on my ViewModel. As such the validation doesn't mark the expected field as invalid.

Is there a way that my IsValid override (or some other method) can mark the child property's value as invalid so I get highlighting?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved