C# - DesignOnly Attribute Does Not Hide A Property In Runtime?

Jan 17, 2010

I'm building a custom web control with a public property which I only want to be available in design time (i.e. make it unavailable in code behind). The DesignOnly attribute promises to do just that, but when I set [DesignOnly(true)] it has no noticeable effect whatsoever:

[Bindable(true)]
[Category("Appearance")]
[DefaultValue(null)]
[Localizable(false)]
[DesignOnly(true)]
public string MyProp
{
get
{
return ViewState["MyProp"] as string;
}
set
{
ViewState["MyProp"] = value;
}
}

The property still appears in code behind IntelliSense. Setting a value to it in code behind works. In these respects, the behavior is just as if the attribute had never been set. And I've cleaned and rebuilt the complete solution. Twice.

View 1 Replies


Similar Messages:

Web Forms :: Changing A Control Attribute At Runtime?

Oct 19, 2010

I'm basically trying to get a div containing a loading gif to show on my page at runtime. I call it from a button click event as well as in the code flow. It was working before I used the AJAX Update Panels. I've since taken them out as they were causing issues with RegisterClientScriptBlock. By the way, does commenting out the AJAX Markup like this...

[Code]....

...remove them from influence?

[Code]....

My code is initiated from the button click event.

[Code]....

The code that does the work goes like this...

[Code]....

View 5 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

MVC :: Retrieve Attribute With Property Name

Sep 6, 2010

What is the best way to obtain an attribute such as the DisplayNameAttribute of a model's property using the property's name. I am using the following method currently:

[Code]....

Looking at this long statement, I cannot help wondering if there is a better way to do it.

View 4 Replies

MVC :: Get Property / Field Value Inside Attribute

Dec 22, 2010

I want to disallow entering html tags inside specific textFields using custom attribute HtmlRemove, but I don't know how can I acces property/Field value? Model:

[Code]....

My custom Attribute

[Code]....

View 8 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

MVC :: Setting Property On A Filter Attribute From Controller?

Feb 17, 2010

here's my situation - I've created some ActionFilterAttributes that I want to apply to a custom Controller class that my other controllers can inherit from. The problem is, I need to set a property on the attribute from the final inheriting controller. So I have something like this :

[Code]....

[Code]....

View 2 Replies

Get DisplayName Attribute From MVC2 Model's Property?

Dec 28, 2010

So, I've got an contact form in my MVC 2 application.

I'd like to programatically email all properties of my "ContactModel".

Here is what I'd like to do in psuedo-ish code:

[Code]....

In case it matters...ContactModel sets up the DisplayName attributes like this:

[DisplayName("First Name")]
public string FirstName {get; set ;}

I'd like to keep this nice and DRY by not repeating the DisplayName names.

Specifically, I'd like to enumerate over each property in my ContactModel, get its DisplayName, and get its submitted value.

View 1 Replies

MVC :: HttpRequestValidationException After Using [SkipRequestValidation] Attribute On Model Property?

Nov 12, 2010

I think I might have stumbled onto a bug in ASP.NET MVC 3 RC. When I setup my MVC2 project in a new MVC3 project, copy paste classes, code, change name spaces, etc, etc, I ran into an issue in the following, simplified for explanation purpose, scenario:

Model:

public class WineDetails
{
[SkipRequestValidation]
[Required(ErrorMessage = "Beschrijving verplicht")]
public string Description { get; set; }
}

ViewModel:

public class ViewModelCreateWine
{
public MasterData MasterData { get; set; }
public WineDetails WineDetails { get; set; }
}

ActionMethod:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult CreateWine(ViewModelCreateWine viewModelCreateWine)
{
GetMasterDataRegions(viewModelCreateWine);
if (Request.Params.ToString().IndexOf("Save") > 0)
{
if (TryValidateModel(viewModelCreateWine.WineDetails))
{
m_wineService.CreateWine(viewModelCreateWine.WineDetails);
return RedirectToAction("index", "Admin");
}
}
return View(viewModelCreateWine);
}

The ActionMethod "CreateWine" needs to call the "CreateWine" method in the WineService so that in the end a new Wine is added to the Database. So far it looks ok. As shown in the above code the [SkipRequestValidation] is set on the "Description" property of the WineDetails model so that the user can add Rich Text to the description and HTML elements are allowed during the Request validation. This works perfectly fine until the Params collection of the Request is accessed in the code to check if the Save button is clicked. When this line of code is trying to execute the following exception is thrown:

Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (ViewModelCreateWine.WineDetails.Description="<p>HTML Content with...").

The same exception is thrown when I put the [ValidateInput(false)] attribute on the action method. When I comment out the "if" statement and its content there is no issue and the model validation works just fine and skips the Request Validation on the Description property as expected.

In MVC2 the above code worked fine with the [ValidateInput(false)] attribute on the action method.As I said I'm not sure if this is a bug, it very well might be my own stupidity, but I thought it would be worth to mention here. So any feedback is more than welcome.

View 2 Replies

Web Forms :: ID Property Of A Control Can Only Be Set Using ID Attribute In Tag And Simple Value

Mar 19, 2013

I am using repeater control and in that i am having div in item template. Now I am setting its id using eval. I want to access this div in item databound for that i am making it runat=server. But in doing so I am getting :

"The ID property of a control can only be set using the ID attribute in the tag and a simple value."

<div id="<%# Eval("RENTER_ID") %>" style="display:none"></div>

How to achieve this functionality. One more thing i am using master page and repeater is in content page.

View 1 Replies

VS 2010 - Hide Treeview At Runtime

Apr 12, 2012

I have master page which contain treeview on left side. I want to act tree view as ToolBox, Solution Explorer, Property Window acts in VS. It is suppressed in left side and as user moves mouse pointer on it, it should come out slowly.

View 1 Replies

Get The Property Value Of A Runtime Object?

Jan 11, 2010

I have a scenario where and array consists of values of different types.

During runtime I need to cast the current index to its type to get its property value

for eg: I have an array events[100];

the current index events[i] could be of any type say TYPE1.The TYPE1 could have multiple properties.During runtime, while iterating, I need to get all the properties and values of TYPE1 by casting the events[i] to the specific type, which I form as xml string and pass to DB.I'm at loss what way of reflection would achieve this.

P.S: I dont know the property of current index at runtime, which is why I'm collecting all the properties and dumping in DB.

View 2 Replies

Hide Property From Assembly?

Feb 17, 2011

i have a property in my project that return is application registred or not and this property is shared that in difrent plaxes taking the value

now there is a problem the user can anywere change the value by calling that property

or is there any way to create a property that can only use in this assembly?

View 2 Replies

Change An Asp Datapager's Pager.PagedControlID Property At Runtime?

Sep 20, 2010

This property was originally set in the aspx file, however I want to change it to select programatically on page load. I set the Pager.PagedControlID property, but I receive the following error message on this line:

Pager.PageSize = Convert.ToInt32(ListLength);

Page properties cannot be set because no IPageableItemContainer has been found. The ID I am using I copied and pasted out of the inline aspx and I checked it is correct.

View 1 Replies

How To Hide A Div Using Visible Property Even It Has A Background

Jan 18, 2011

I have the following div:

<div visible="false"
style="background-image:url('../Contents/Images/item-background-selected.png'); width:113px; height:58px; background-repeat: no-repeat; position: absolute;" />
<div>

It's still visible in spite of the visible property is set to false. but when I remove the background-image from the style it's hidden.

How can I hide it with keeping its background?

View 2 Replies

Custom Server Controls :: Category Attribute Of User Control Property Does Not Work Correctly In Categories Tab

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

How To Hide Property Of Custom Control In Aspx Page

Feb 8, 2010

I'm writing ASP.NET custom control, and I want it to have a few properties which should be visible only from code behind during run-time - I mean, these properties should not be visible both in a designer and in a aspx code of page containing this control. I've tried to use following attributes:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public List<Item> SomeData
{
...
}

but unfortunately this property is still visible in an Intellisense combobox when editing aspx page. Is it possible to hide this property everywhere besides server-side code ?

View 2 Replies

Forms Data Controls :: Cannot Assign Values To Checked Property Of Checkbox At Runtime

Apr 22, 2010

I have a ASP.Net page that has a gridview control. This gridView control has a checkbox controls. I would like to assign a boolean value from a database field to the Checked property- Checked='<%# Bind("RESULTS") %>'.

When page loads,I get error - Specified cast is invalid!

The code is as follows...

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="dsResults"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px"
CellPadding="3" OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:TemplateField HeaderText="COMPLIANT" SortExpression="RESULTS">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("RESULTS") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("RESULTS") %>'
Enabled="False" />
</ItemTemplate>
</asp:TemplateField>

Note: If a constant value is passed at design time it works fine. But i want to assign the value at runtime using Bind.

Environment details: VS 2008, ASP.NET 2.0 and .Net Framework 3.0 & C# language.

I tried returning values like 0s and 1s, Ys and Ns and True and False from a database field. But i still get the above mentioned error.

I tried retreving the value in OnRowDataBound event using Eval, since Bind is not available in code behind. But it would make the field readonly and i cannot edit and update the Results field.

Even though there is a value returned by the query why does the Checkbox does not assign the value using <%# Bind("Results") %> to Checked property instead throws error - Specified cast is invalid.

how i can edit and update Checkbox.

where did the Bind method of ASP.Net 1.x is moved? How can i use Bind in code behind of ASP.Net 2.0?When i type DataBinder the intellisense shows Eval and other stuff but i don't see Bind that would solve the problem of two- way binding.

View 16 Replies

C# - Microsoft JScript Runtime Error: Object Doesn't Support This Property Or Method

Jan 28, 2011

I am trying to use jGrowl in ASP.NET, but am getting a Microsoft JScript runtime error: Object doesn't support this property or method error when trying to run the page in IE.

<link rel="stylesheet" href="css/jquery.jgrowl.css" type="text/css" />
<style type="text/css">
div.jGrowl div.smoke {
background: url(images/smoke.png) no-repeat;

[Code]....

View 1 Replies

Microsoft JScript Runtime Error: Object Doesn't Support This Property Or Method

Jun 9, 2010

I am trying to validate my gridview checked checkboxs, using code below.

I get "Microsoft JScript runtime error: Object doesn't support this property or method" error when button is clicked and i used breakpoints to check strangely, i am getting back gridViewx count=3 in javascript function. my gridview has nested gridview?

CodeBehind.aspx
page on_load
ActiveAssignButton.Attributes.Add("OnClick", "return IsCheckBoxSelected(" & GridView2.ClientID & ")")
html page
function IsCheckBoxSelected(gridViewx) {
if (gridViewx != null) {
var chkBoxes = gridViewx[0].getElementsByTagName("input");
for (i = 0; i < chkBoxes.length; i++) {
if (chkBoxes[i].type == "checkbox" || chkBoxes[i].type == "CHECKBOX") {
if (chkBoxes[i].checked == true) {
return true;
}
}
}
alert("At least one ticket needs to be selected!");
return false;
}
}

View 3 Replies

C# - Microsoft JScript Runtime Error: Object Doesn't Support This Property Or Method?

Mar 8, 2011

I am writing a Web Application in ASP.NET using C#. Whenever I run it, I get three types of Runtime Javascript Errors.

My Problem is that even though I am running a new Web Application with out any modification, then I also get the same errors.

These are the errors:

Microsoft JScript runtime error: Object doesn't support this property or method
at
document.addEventListener("mousemove", updateLastMouseMoveCoordinates, false);
Microsoft JScript runtime error: Object expected
at divSurveyInit();
Microsoft JScript runtime error: Object doesn't support this property or method
at enter code here:
document.addEventListener("mousemove", updateLastMouseMoveCoordinates, false);

View 2 Replies

Web Forms :: Hide Inherited HyperLink-class CssClass-property?

Mar 24, 2010

Well..the title sort of explains the problem..

I have a class that inherits the HyperLink-class, but I want to "hide" the CssClass-property from the intellisense and also from the "designer-view"..

I have tried the following:

[Code]....

View 1 Replies

C# - Base Page Property Show Up In @Page Attribute?

Jan 27, 2010

I have create a list of public properties in our custom page. However, when I want to assign the property on any aspx file, it does not show in intellisense and when I use it it said it is a invalid attribute of element "Page".So, 2 question.How do I make it such that it shows up in intellisense?Can I set any localize variable as a value of the property in the page directive?here is the property on my base page:

/// <summary>
/// Robot meta tag
/// </summary>

[code]...

View 1 Replies

Forms Data Controls :: Attribute 'onchange' Is Not A Valid Attribute Of Element 'TextBox'

Mar 31, 2011

<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" onchange="calculate()" runat="server" Text="0"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

I'm getting this error on the above markup: Message 1 Validation (ASP.Net): Attribute 'onchange' is not a valid attribute of element 'TextBox'.

View 2 Replies

Web Forms :: Getting Error / Unrecognized Attribute 'targetFramework'. Note That Attribute Names Are Case-sensitive

Mar 17, 2011

I have a problem with my web site 1stSigBdeAssn.org. I have made no changes to the site but I now get the following error message:

Parser Error Message:

Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

Source Error:

[code]....

View 4 Replies







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