Is it possible to do something like this inline in an ASPX page?
<%= Me.SomeExtensionMethod() %>
I can't seem to figure out how to get this to work properly. I'm receiving an error saying that "SomeExtensionMethod" is not a member of the current Page object. I've added the necessary <%@ Import Namespace="..." %> directive at the top of my page. This Does work in code-behind.This isn't vitally important, but it would be good to know how to do in the future.
public static class PageExtensions { public static int GetUserId(this Page targetPage) { var user = Membership.GetUser(targetPage.User.Identity.Name); return (int)user.ProviderUserKey; } }
Now in a page I need to use this method in a static WebMethod, so I have added another 'extension method' to PageExtensions:
public static int GetUserId() { return (int)Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey; }
and I call it as follows in my WebMethod: PageExtensions.GetUserId()
For reasons that are probably not worth mentioning in this post, I have decided to stop using ASP.NET controls and simply use regular HTML controls for my .aspx pages. As such, to dynamically generate HTML, I use c# inline to the .aspx to do what I need to do.
For example: this .aspx snippet shows how I am dynamically creating a <select> element where the <option> elements are driven by looping through a generic list of objects.
<select name="s"> <option value="-9999">Select an entity...</option> <% foreach (MyEntity e in this.MyEntities) {%> <option <% if (MyEntityInScope.ID == e.ID) { %>selected<%} %> value="<%= e.ID %>"> <%= e.Name%></option> <%} %> </select>
Functionality-wise, I prefer this method of creating HTML (I feel more in control of how the HTML is generated vs ASP controls). However, syntactically (and visually), I think it's cumbersome (and ugly).
Is there a "better" way (another syntax) to dynamically generate HTML w/out resorting to using ASP.NET controls?
I want my site visitors to be able to navigate to a page without having to type the .aspx extension. For example, if I have a page file named info.aspx I want site visitors to be able to go to that page with a URL like this: www.mysite.com/info without the aspx extension. Is there a way to do this in the web.config file?
I have an extension method which I can use from the .cs codebehind of an aspx page, but if I try to do it in a code block in the aspx, it can't find the extension method. Is there something I need to add to the page?
I'm searching for some extension methods that helps programming in ASP.NET. Some functions to work on controls, validators, AJAX or programing in C# in general.It could be methods library or your own methods.Do you know any source of those methods (other than CodePlex - that is good source of generic extensions) especially for ASP.NET?
I have got 3 aspx page and a usercontrol on each page have an email placeholder in it. What I want to acheive is when the customer click on the usercontrol email placeholder, certain method on a particular page should trigger. See below for the code:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text; using Tangent.Breakingfree;
[Code]....
Also I have got another method on a different aspx page, I want to trigger that method when the client is on that page. The user control should trigger the right method depending on the page user is currently on.
I'm using ASP.NET with VB, and .NET version 3.5. In the project, I've got some utility functions that I call from expressions in the aspx pages and also in code behind. This all works fine on my local machine, but when I deploy to the production server, I get this compilation error on each of those utility methods:
BC30456: 'XXX' is not a member of 'String'.
where XXX is an extension method defined on System.String. I'm baffled about this for a number of reasons:
Why is ASP.NET compiling anything at all, since I've precompiled the application and put everything in the bin directory. ASP.NET knows the functions are there because they work in code behind. It's only when used in the aspx page that I have this problem. (e.g. if I do something like this: <%= "A string to XXX-ify".XXX())%>) This method is public, which I verified with Reflector. I imported the relevant namespaces in the web.config file, and I can see that these namespaces are being imported in the call that ASP.NET makes to the compiler.
Note , that i'm new to c# so it might not be a problem.first , what is the exact meaning of @ in Razor ?does it mean WebPage.Response.Write ?next, i designed an extension method to WebPage ( by the way that is the coolest feature ever in c# )in my Razor code , to use it in a webpage , i must write @this.MyExtensionMethod() instead of @MyExtensionMethod().So why is it? because @this.MyExtensionMethod() and @MyExtensionMethod() should be the same ?
With regards to the Razor view engine, say I want to render Html.TextBoxFor<SomeModel>(i => i.Name), it doesn't seem that the inline syntax works as in:
@Html.TextBoxFor<SomeModel>(i => i.Name)
This doesn't seem to work because it interprets the generic as an HTML tag. I could use a code-block approach, but then what's the best approach to output the content? The HTML string returned from this method, do I response.write it, or is there a syntax for it, or what's the approach?
I am trying to create an extension to extend the HtmlTextbox methods to allow our developers to add onkeydown inline javascript to auto click a button with a name they specify.
I have a web site project using the .NET 2.0 Framework that I am working on in Visual Studio 2008. I am using a third-party DLL in my project. I have added a reference to the DLL in my project and I can use everything as expected, including a number of extension methods for certain objects. Intellisense sees these extension methods, and I am able to make use of them and I can build my project on my local machine without any errors.
However, when running my website on a production server, I get a Compilation Error saying that the extension method I am trying to use could not be found. I can use everything else in the DLL besides the extension methods on the production server.
This is my first exposure to extension methods and understand what they are, but I can't seem to figure out why I can't make use of these methods outside of my local machine.
In the previous version of our application we worked one we used MVC 1, so no area's. Following the ASP.NET MVC Best Practices by Kazi Manhur, I Created Extension methods of UrlHelper to generate your url from Route
Now with the new version, we are using MVC 2 and Areas. I was just wondering if one should implement it as before or have a new "best practice" regarding this emerged?
What I'm doing right now is:
1) Create a route in my area's route registration:
[Code]....
2) Creat an UrlHelper Extension method:
[Code]....
3) then just call it like this:
[Code]....
While typing this I started wondering what is the use of the ID you specify for the Area route..cant one just call the route using that?
I'm developing a web site, and i'm using infragistics for web, but I want to use in some pages silverlight controls (Infragistics too). Is there a way to access a silverlight control's properties and methods from an aspx page?
We say that "GroupBy" and "OrderBy" methods from LINQ as Extension Methods.Then how about "variable.ToString()" and "string.Split()" menthods. Are these Extension methods.
Is it possible to do things in a PHPish way in ASP.Net? I've seen <%= %> but I've tried it and couldn't get it to work. The PHPish equivalent of what I want to do is