Best Way To Generate Url Via Page.GetRouteUrl In A Helper Class?
Nov 5, 2010
I have just added routing in a new asp.net 4 web forms application, and have got my route table set up ok and page requests are working fine. What I now want to do is use the Page.GetRouteUrl method whenever I need to generate one of my seo friendly Url's. I started to implement this across various pages then thought it might cut down on code a bit if I had a method in one of my own helper classes, that constructs this url (using the Page.GetRouteUrl method) as I might have several parameters that need to be specified against the Page.GetRouteUrl method each time.
However, within my helper class, it doesn't know what 'Page' is. I was thinking I could pass in 'Page' from the page that wants a routed url to be generated, but in some cases I want to construct one of these Url's in another class which doesn't know what 'Page' is, and in that scenario wouldn't be able to pass it in as a param (and therefore wouldn't be able to use the Page.GetRouteUrl within my helper class). What is the normal approach when wanting to use Page.GetRouteUrl within classes that don't have an instance of the Page object?
View 1 Replies
Similar Messages:
Dec 17, 2010
Is there a way to pass a reference of a page to a helper class? Scenario: [ASP.NET 2.0 Web Application] The page is a content page which has a MasterPage. The page calls a method in the helper class and passes the page byRef as an argument. The method in the helper class tries to find a control on the passed in page and set values. Problem: Only the MasterPage is being exposed and not the page I am trying to pass. Any recommendations on passing the page so that I can set the values of the controls within it?
View 5 Replies
Jun 30, 2010
I have a class instance which is created by using Activator.CreateInstance() method. That class instance contains helper methods which are frequently used throughout the application. In order to avoid creating the instance multiple times, I'm just thinking about implementing an appropriate caching mechanism. The following consideration should be taken into account:
1) I can't use static class and methods.
2) There are around 6 instances (1 instance per class) per App Domain.
View 4 Replies
Sep 1, 2010
I'm facing odd problem with Page.GetRouteUrl() method. It is working only on regular content pages and doesn't want to work on my master pages. I'm using simple snipet: <%# Page.GetRouteUrl("Default", null).ToString() %>, when I put it on some page, it generates "/Default", when I put it on master - I get "". I've tried calling Master.GetRouteUrl() instead but still no luck, it always returns empty
string. Funny thing is that it works in code behind (bothPage.GetRouteUrl() and MAster.GetRouteUrl() works) of the master page, only markup seems to be affected. I bet it is somehow related to the configuration since I have recently moved from ASP .NET 3.5 to 4.0 on IIS7 with integrated pipeline.
View 5 Replies
Jul 1, 2010
I wanted to write a code for JQgrid in asp.net .I have tried the same in asp.net MVC,but i want it now in asp.net .n MVC we use Helper class,and return json data,so what to do in asp.net where helper class can not be used.Serialization can be done with data to get it in json.,but what about Htmlhelper.
View 2 Replies
Mar 30, 2011
When is it appropriate to create a helper class for a sql server database using the asp.net framework? Basically I'm trying to create a minature wiki (with multiple pages) and storing all of the data/strings for a specific page into a table on it's own.
View 3 Replies
Jan 24, 2011
I need to use the standard ASP.NET membership database tables in plain winform projects, and I DO NOT WANT to add the ASP.NET dll, because my app must run with .NET Client framework, and not full framework. Does somebody knows of a helper class that links to ASP.NET tables in plain vanilla VB ot c# code? I mean with functions equivalent to CreateNewUser, CheckUserCredentials, isUserinRole, RoleList etc...
View 1 Replies
Jun 30, 2010
I'm working on a page with two sets of collapsable panels. using nHibernate) I get category objects with a list of items in them, and for each category generate a left panel and right panel. In both panels, there is a ListBox. Items are pre-populated to the left list box and the user can select and move items into the right list box (under the corresponding category.) As I've built and worked on it, I ended up with a lot of generic methods like buildPanel(side,categoryID) and then ended up with a lot of repeated if statements inside them to differentiate between the two sides
if type=PanelType.Left then
set these 5 id strings to access components
else
...
The code got messy, so I moved a lot of the logic and static builder strings for the component ids into a private helper class in order to make other parts of the main class easier to read and follow. The problem I see is that the private class is extremely dependant on specific structures in the parent class. There's a very minimal amount of encapsulation going on and I'm possibly making the logic harder to follow even if the individual components in the code are easier to read.
My question is: When you're using a private class like this, is it acceptable to have it tightly integrated with the parent class (since it's private and implemented in the same file), am I better to refactor again and find a way of either simplifying my original code to be as short as possible without the helper class (stick all category/panel functions in one spot and hide them in their own region when I'm not using them), or should I move towards putting more of the logic in the helper class and simply mapping my events directly to the subclass. After typing all this out, I'm leaning towards the last option, but I'm still torn/confused about the whole thing...
View 2 Replies
Mar 2, 2011
I was using the default MailMessage and SmtpClient classes for creating and sending HTML emails from a web forms website. The problem is I have a lot of hard coded HTML for formatting the email that gets sent. Is there a class that helps format emails for .NET?
View 2 Replies
Feb 3, 2010
With asp.net MVC 2, I have been trying to get Matt Hawley's Localization helper to work in my web application, but I am getting stuck feeding a null into the Language string variable. I can't figure out why I am doing this.
namespace MvcLocalization
{
public abstract class LocalizedControllerBase : Controller
{
public String LanguageCode { get; private set; }
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
LanguageCode = requestContext.RouteData.Values["languageCode"].ToString();
if ( !AppConfig.SupportedLanguages.Contains(LanguageCode) )
LanguageCode = AppConfig.DefaultLanguageCode;
System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture(LanguageCode);
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
base.Execute(requestContext);
}
}
}
View 1 Replies
Sep 18, 2010
I have a static class (an helper class) which has the responsability to create control and add them to a panel passed by parameter, this method is used by a lot of
View 5 Replies
Mar 15, 2011
recommend a data access class / helper class for Access databases, similar to the sqlhelper class found in the (Data Access Application Block)?
View 6 Replies
Mar 16, 2011
I have been trying to figure out how to use the Routing features with ASP.net 4.0 WebForms. I added a route to my route collection:
void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute(
"about-route",
"about/",
"~/About.aspx"
);
}
In my master page I tried to do the following: <asp:HyperLink ID="asdf" runat="server" NavigateUrl='<%= GetRouteUrl("about-route", new {}) %>'>Test</asdf> I got a compiler error: Server tags cannot contain <% ... %> constructs. What is the proper way to create a route URL in a server control in Web Forms? I also need to include it in the following:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="ROUTE HERE" Text="Home"/>
<asp:MenuItem NavigateUrl="ROUTE HERE" Text="About"/>
</Items>
</asp:Menu>
View 1 Replies
Aug 24, 2010
I'm building my asp.net 4.0 website with url routing. It works great, except that I have stumbled upon one problem. The problem is that when a logged in user is on one of the non-public pages and gets loged out, the return url is set to the page he or she was previously visiting. When logging in again, the ReturnUrl is non routed url (something like login.aspx?ReturnUrl=somethingsomething). This poses a problem for some of my pages where I have a default value stored in the route; it simply doesn't get picked up with the non routed url of the ReturnUrl.The result is a broken page (404).
View 2 Replies
Jan 23, 2010
from years go i use "SQL Helper" class that exist in Microsoft Application Blocks for .NET and i used it for about 1 year in many projects but after that many senior recommend me not to use as it's have many problems in big projects and i let it but know in a new company they want to use it in a projects ... Could any make his recommendations about it / and if it's really excellent to use it have already issues ?Is there any other good solution rather than SQL Helper ?
View 2 Replies
Jan 4, 2011
To be able to implement paging i need to create a helper class (as mentioned on one example in the net ); so i have created a class that encapsulate the paging logic
public class PagingList<T> : List<T>
.
..
but when i reference this class in my view using the code below:-
Models.PagingList<Article>
The following error occurred. Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0246: The type or namespace name 'Article' could not be found (are you missing a using directive or an assembly reference?) Source Error:
[Code]....
Source File: c:UsersMohannadAppDataLocalTempTemporary ASP.NET Files
oot1f3f505f568b8e69App_Web_index.aspx.82d38c66.ffjpt45i.0.cs Line: 172
Show Detailed Compiler Output:
View 9 Replies
Nov 7, 2010
I have a generic class and I want to generate a URL when given the controller and action values. The most obvious method is Html.Action(controller, action), but this can only be called within a View. I tried adding 'using System.Web.Mvc;' to my class, but this doesn't give me the Action() method. I also tried converting this to an HtmlHelper class, but again no luck.
How do I generate a fully qualified URL within a class using the controller and action names?
View 1 Replies
Jun 14, 2010
I am trying to generate a random number from within a class and am getting "Type 'Random' is not defined" - does anyone have any ideas. Here is the code
**note the code works on an aspx.vb page, but not from within my class
Dim RandomClass As New Random()
Dim RandomNumber As Integer
RandomNumber = RandomClass.Next(3)
View 3 Replies
Jan 7, 2011
I create a database with more than 10 tables, how can I automatically generate business object class inside asp.net C# project?
I hope that one expert can give me steps for how to do that?
View 3 Replies
Nov 26, 2010
How to generate a path/url from a Route in the Routes table? only this time I'd like to be able to build a url within one of my Model (partial) classes. I'm defining a new property that will contain the text to be rendered within an rss feed, and want to inser urls (within anchor tags) in this text. I found the UrlHelper.GenerateUrl method, but get unstuck once I get beyond passing in the appropriate RouteName, ActionName and ControllerName.
View 1 Replies
Jun 10, 2010
I would like to generate my links automatically via a static class in each of my aspx pages (or in a common BasePage).Currently I use this:
private const string TEMPLATE =
"~/One.aspx";
public static string Link ()
(
string link = String.Format(TEMPLATE);
return link;
)
But the name of my page, One.aspx is hardcoded. Is it possible to generate the path instead of this hardcoded constant TEMPLATE. You should know that I do not instantiate the class before creating the link.
View 1 Replies
Feb 25, 2011
I have created an extended method for DataTable. I want to generate a class automatically in my solution when i call that method while writing a code as Visual studio does when it doesnt find the method.e.g mytable.mymethod(); Generate a class
View 2 Replies
Jul 6, 2010
i wanna use to subsonic 3.0.4 but i dont know, how can i start to generate class and use to new Template of T4. example: create new solution for generating to table's class and add to my project. ??
View 2 Replies
Mar 2, 2011
Currently I have a class that represents a document. This document needs to be displayed as HTML. I would like to have a method to call such as GetHTML() that would then call GetHTML() on any properties/sections of the document that needed to be rendered. I was initially thinking about using linq and XElement but am wondering if that may cause issues with certain tags in HTML. Would I better off using an HtmlTextWriter?
View 2 Replies
Feb 12, 2011
I'n trying to setup a view template dynamically using a foreach loop. The view template is as follows:
[Code]....
My metadata class is as follows:
[Code]....
The partial seems to render the labels correctly, displying the appropriate name for the fiields that I have annotated. However the value of the fields is always set to the class property name itself rather than the value of the given record itself.Now I'm pretty sure my problem is something stupid, but I can't see what I am missing. I followed Brad Wilson's guide here adjusting it for Razor's syntax:http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-4-custom-object-templates.html
View 4 Replies