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
Similar Messages:
Feb 15, 2011
I am trying to put a usercontrol in a popup.. finding code using any way (ajax,javascript, jquery). i am unable to provide the control in popup.
View 1 Replies
Mar 15, 2011
I've got a simple ASCX user control (non-MVC). The user control has a property on it (let's call it Title or something).
I've also got an MVC Partial View which contains the user control.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<SomeModel>" %>
<%@ Register TagPrefix="tag" TagName="Control" Src="~/path/to/ascx/control.ascx" %>
... snip ...
<tag:Control ID="myControl" runat="server" />
What I'd like to be able to do is something like this:
<tag:Control ID="myControl" runat="server" Title="<%= Model.Title %>" />
... so that I can access some property of the model inside my Control.
Unfortunately this method doesn't work, as I get a message saying "This is not scriptlet. Will be output as plain text".
Is what I'm trying to do even possible? If so, how I can try and do it?
If it's relevant, this is a .Net 4 project, with MVC 2 components.
View 1 Replies
Mar 5, 2011
I have a function that Localize the text of my control.
// code behind
lblName.Text = Localization.GetLocalValue( "Updated" , this.Path );
and I know that i can call a function inside ascx file.
// ascx file
Text='<%#Global.Convert( (DateTime)(Eval("CreatedDate")) %>'
How can i Get Path Property in ascx file To call GetLocalValue ?
View 1 Replies
Mar 29, 2011
In ASP.NET, you can add custom HTML tag attributes to a UserControl via
myLabel.Attributes['my-custom-attribute'] = "someValue";
// or Attributes.Add()
but how can I add an attribute that doesn't have a value? For example, (and I'm not saying that this is what I need) the W3C specification only needs the checked attribute present in a checkbox to consider it checked (instead of checked='true' or something).
<span ID="ctl-blah-blah-myLabel" my-custom-attribute>some text</span>
I'm looking into using something like this to tag specific elements on my page for some client-side behavior. I know that I can do the same with classes, but (1) classes are iffy to manipulate server-side, and (2) I kind of don't want to pollute my class declarations just for tagging (that may be weird for some, I know).
View 3 Replies
Jul 28, 2010
if Panel have any aspnet control,panel not popups.otherwise working.whats wrong here ? is it impossible ?
[Code]....
View 1 Replies
Jan 19, 2014
I have two files in my project. One is user control (popup) customerpicker.ascx and one is default.aspx page. In customerpicker I have dynamically generated gridview and 'select' column with SelectButton.
What I want is this: When I click on 'select' on random row in gridview, then I like to display value from selected row immediately (like ajax) to aspx.page. How it is possible?
There is part of my code in .ascx:
public string showOnaspx { get; set; }
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridViewRow row = GridView1.Rows[e.NewSelectedIndex];
showOnaspx = row.Cells[1].Text;
e.Cancel = true;
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
//row[i].Attributes.Add("onclick", "$('#ContentIndex_sometextbox).val(" + row[i].Cells[1].Text// + "); $('#Close').click();");
}
I also tried with jqeury (comment in selectedindexchanged function), but it does not work well, because user have to click SELECT two times to effect.
View 1 Replies
Apr 14, 2010
I am working in a CMS where we use tokens ( which is turned into a user control. Is there a way to add the user control into an attribute value for our template style? example :
<div class="<$tokenName/$>" />
this currently outputs an encoded user control, which is then not parsed by IIS.
View 1 Replies
Feb 22, 2011
I am using a third party control which not shows any onclick event option, since its a user control how can i add onclick event to it?
View 3 Replies
Nov 10, 2010
how to use gridview usercontrol (Ascx) and sql pass to aspx page
View 4 Replies
May 19, 2010
I have an ASCX that inherits from a WebControl that has a 'CustomConfiguration' property of type CollectionConfigurationItem. This configuration gets set elsewhere in the code, so by the time it gets to the ASCX it is set up to how I wish to use the data. At this point I'd like to render out another control using this configuration, like so:
<modules:DataModule runat="server" CustomConfiguration="<%# Model.CategoryListConfiguration %>" />
However, breaking into DataModule always results in 'CustomConfiguration' being null, which is the default value for the property. I've tried adding a Bindable attribute to the property but to no avail, and when I set an EventHandler for the DataBinding event on the DataModule it doesn't even get called.
How can I set this custom-class-typed property from the markup or, failing that what's the second-best method of getting this to work?
View 1 Replies
May 20, 2010
How do I go about providing localised text for items in a custom web control? I had thought that I just need to add meta.resourcekey tags to the control items and then define and fill some resource files called mycontrol.ascx.[lang].resx but that doesn't seem to work.e.g.
MyControl.ascx
<asp:Label ID="Label1" meta:resourcekey="Label1" runat="server" Text="Oops!"></asp:Label>
MyControl.ascx.de.resx
Label1.Text Donner und Blitzen!
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
Nov 11, 2010
I am getting required functionality when I am adding javascript to grid column in aspx page. but i am not getting the same functionality when l am loading ascx page in my aspx page.
View 6 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
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
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