C# - ResolveURL Not Resolving In A User Control?

Mar 31, 2010

I'm trying to use ResolveUrl() to set some paths in the code behind of a custom ASP.NET user control. The user control contains a navigation menu. I'm loading it on a page that's loading a master page.

When I call ResolveUrl("~") in my user control it returns "~" instead of the root of the site. When I call it in a page I get the root path as expected. I've stepped through with the debugger and confirmed, ResolveUrl("~") returns "~" in my user control code behind.

Is there some other way I should be calling the function in my user control code behind to get the root path of the site?

View 4 Replies


Similar Messages:

C# - Is It Possible To Override ResolveUrl

Dec 14, 2010

I use the following my .net applications to resolve the path to an image or css file or javascript file.

<%=ResolveUrl("~/Scripts/myscript.js")%>

<%=ResolveUrl("~/images/myimage.jpg")%>

All my pages and controls inherit from a base page or base user control.

I have tried but didnt succeed in overriding the ResolveUrl method so that I could include some custom logic in the files path.

how I might override the ResolveUrl method? Alternative is to create my own custom method that does similar but would prefer to work with ResolveUrl.

View 2 Replies

C# - ResolveUrl Without A Page

Feb 4, 2011

I am looking for a way to resolve a relative url the way you would with a page or control instance (MSDN Docs) such as:

Page.ResolveUrl("~/common/Error.aspx");

...but when I only have an HttpContext available to me, such as when I am in a HttpHandler.

Will I need to use a custom function, such as the one seen here?

Or is there a way to get at the underlying function used by the Page.

View 2 Replies

C# - IIS 5.1 Not Resolving Virtual Directory?

Oct 13, 2010

I set up a Virtual Directory called 'Site'. I browse to [URL].In the source file, the relative paths are coded as '/Page1.aspx', for example, and it has worked in the past.I'm using Win XP Pro SP3 and IIS 5.1. Any ideas on what might be causing this behavior?

View 3 Replies

ResolveUrl In Static WebMethod?

Jun 23, 2010

How do you resolve a url like "../../images/test.png" to [URL] in a static asp.net web method?

View 2 Replies

C# - Resolving .NET Assembly Reference To A Different Name?

Nov 24, 2010

My project references Library1.dll and Library2.dll. Library2.dll has a dependency on Library1.dll, but it was compiled to reference it by a different name, Library1.Net40.dll. there an nice way tell my application to redirect all references for Library1.Net40.dll to resolve to Library1.dll? Maybe something similar to the way you can redirect versions using a <bindingRedirect>
I've got a solution that handles the AppDomain.AssemblyResolve event, but it's a bit of a hack and am hoping there's a better way to do this.

View 1 Replies

MVC :: Model Is Resolving Unpredictably?

Feb 23, 2011

The model for the View in question has two values that are being resolved as the same, when they're not. Here's the offending code:

[Code]....

They both resolve to 182. The first value is actually 2, and the second is 182. My first thought was that an inaccurate value had been assigned to ID, but I did a test, and here's where it got really weird. The test:

[Code]....

Results? 182, 2, 182. When the Model.ID was resolved inside of the Html.Hidden control, it resolved to 182. Outside of that control, it resolved correctly to 2. Absolutely no processing happens between these two being rendered - it's just as I've listed above.

So I did another test and stepped through the code. It turned out that the value wasn't being resolved incorrectly - just rendered incorrectly. When the execution gets to the hidden control with Model.ID, the value is correct (2). As I step through the entire view code, the value does not change. It remains as 2. Everything should be good. But when the view renders and I look at the source, it's been changed to 182. This is seriously messed up.

Another test - I changed the name of the control:

[Code]....

Now it resolves to 2, the correct value, and keeps that value when it renders. Somewhere the "ID" name was being overwritten. This still seems buggy to me. Just like the issue I posted with the Html.DropDownList, when stepping through the code the expected value is assigned, but when it rendered to the page, the value has been silently changed. The Html.DropDownList does something like this, as it tries to match up the selected option to the model, but the expected behavior would be to allow explicit code to override defaults. But no, the DropDownList just assigns the selected value to whichever item a condition tested true for, and then silently drops it in favor of matching from the model.

This silent failing from over-adherence to convention is driving me nuts. At least in the Html.DropDownList I have a good idea of where the problem is coming from. Though there might be another control with a name of "ID" on the page (the code shown is from a Partial View), the model is correctly resolving as it assigns these values. It assigns the correct values, and then renders incorrect values.

View 3 Replies

Images Not Resolving In Asp Webapp (c#)?

Mar 22, 2010

I've been working on an asp web application, which involves the user registering details of a person, including an image of the person. The file name of the details/image are stored in a SQL database with the image filename storied in an NVARCHAR column, rather than storing the actual image in the DB.I created a directory C:Images to which the image files would be stored by the application. The application works correctly in as far as it moves the images to this location, but when I open the page which would display the details/image the image never renders.

I got round this during development by having the image stored in a folder which was part of the project, but after release of the project to the server, the application refuses to allow the image to be saved in any directories within C:Inetpubwwwroot .So I need find out why the images won't render when they are stored in folders not within the project.I've checked the source of the HTML page which also points to the correct location and file name:

img id="ctl00_MainContent_CandidateImage" src="C:Imagesapplicant11.jpg" alt="Candidate Image" style="border-width:1px;border-style:solid;height:208px;width:208px;"

The code behind page renders the image in the code below:

// CandidatePhoto filename retrieved from DB.
CandidateImage.ImageUrl = "C:\Images\" + CandidatePhoto;

View 6 Replies

Web Forms :: Use Page.ResolveUrl In Web.sitemap?

Feb 14, 2010

I want to use .sitemap file,but how to use Page.ResolveUrl in it. Because i have used UrlRewriting so it url are virtual.tell me if another way of doing this.

View 1 Replies

MVC :: Razor And ResolveUrl / Getting Error CS0103

Aug 22, 2010

I have the following:

[Code]....

And I am trying to do the same with Razor:

[Code]....

But I keep having the error:

Compiler Error Message:

CS0103: The name 'ResolveUrl' does not exist in the current context

What am I doing wrong?

View 6 Replies

MVC :: Resolving Links Tags In Master Page?

Feb 22, 2010

Only in master file, and only in <link> tag Links.Content.Site_css doesn't work. That is, if I have
[Code]....
If I put the same thing in <title>; or if I put the same link tag in a regular aspx file; or if I use Links.Scripts.jquery_js - everything seems to be working fine. Is there anything specific for resolving <link> tags in master page? I am using MVC 2 RC2

View 4 Replies

CSS And Javascript Files Not Resolving After Migrating App To Win 7 Dev Machine

Jan 2, 2010

I have a ASP.Net 3.5 web site I developed on my old XP sp3 machine. The app uses Master Pages and App_Themes that include style sheet and images - and also an image folder off the main root for most of the images. There are also some javascript files in a /scripts folder for jQuery and one other. I now have a brand new Win 7 64-bit dev machine and I migrated the app there. It compiles and runs fine - even through the Enterprise Library hitting the SQL database - the only problem I am haveing is with the CSS and javascripot files. For some reason that I cannot detect they are not resolving when I run the app. The CSS does resolve at design time and all the styles are rendered correctly in the designer. This leads me to believe that it may be an IIS 7 issue?

View 2 Replies

Finding ResolveUrl/ResolveClientUrl Equivalents For Razor?

Feb 16, 2011

So I've started using the <%: Url.Content(~/site/blah) %> syntax as standard for CSS, JScript and Image urls - solves a lot of issues indeed; and it's at least consistent beween WebForms and Razor pages (not all of my devs will be doing Razor, and yet they will still be working on this platform I've produced).

However, for something that I'm doing at the moment I could really do with a way to take a relative Url written in a Razor page and, at run time, resolve it to the correct server side file, before turning it back into an absolute Url for the client. Url.Content doesn't do anything with relative Urls.

So, basically, I want either an equivalent of ResolveUrl or ResolveClientUrl at the Razor level.

I would like this to enable terser (and more tolerant to renaming) resource paths in some of my MVC views, which can be a few folders further down from the root, and whose content folder would be more easily expressed as a relative path - so I could have:

folderfolderviewssharedlayout.cshtml
and
folderfoldercontentsite.css

(I've inferred the use of a layout page, also, to mirror the kind of issues that are addressed by ResolveUrl and the re-basing that WebForms does)

Using Url.Content as it is, I would need to specify the full path:

Url.Content("~/folder/folder/content/site.css")

But what I would like is

Url.Content("../../site.css")

And have that work, of course, regardless of how many paths there are in the current request's route.

Of course I can get this to work in WebForms, if I ditch the Url.Content call and just rely on url rebasing.

Is there any equivalent in Razor?

View 1 Replies

Server Controls In User Control Are Null When User Control Serves As A Base User Control ?

Jun 4, 2010

I don't think I understand fully how ASP.NET does inheritance of controls.I have a user control, ucBase, which has an asp.net label in the ascx file. Code behind references the label and it works fine during run time if the control is not a parent for another user parent.

If I have another user control, ucChild, inheriting from ucBase, the label in ucBase's code is always null. ucChild has no controls in its ascx fileThe server controls (like the label) needs to be declared in the ascx file and not created programmatically.What needs to be done for ucBase to see its own controls when it's a parent user control?

View 1 Replies

Web Forms :: Accessing A Public Property Of A Nested User Control In A Master Page From A Pages' User Control?

Sep 10, 2010

I've got a web site that has a master page and that master page (mpMaster that has a user control ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page
and on this page I have another user control (ucPageControl), I need to find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all?

View 5 Replies

ResolveUrl Path Receives Error: "Too Many Characters In Character Literal"?

Apr 1, 2010

I am trying to do a correct path javascript like this to an image but when compiling this code, I receive the error:

"Too many characters in character literal"

I have tried to figure it out but it seems correct but something might be wrong. I have to use ResolveUrl to go back to the rootdirectory.

[Code]....

View 2 Replies

Web Forms :: Assign User Control From Another User Control ? Giving Error Object Reference Is Not Set An Instance?

Feb 17, 2011

I am trying to assign user control from another user control ..first time its binding control successfully but when we refresh the data its giving error

saying "Object reference is not set an instance".

how to refresh data from another user control ...

My senerio below :

1 Aspx page

2. User control

calling usercontrol databinding method from aspx page but once it get refreshed ,not allowed to bind it again..

View 2 Replies

User/server Control With Custom List Items / Create A Simple Menu User Control

Feb 18, 2011

I'm attempting to create a simple menu user control just as outlined here.

The attached code results in an "Object reference not set to an instance of an object" error, but I can't figure out why.

<%@ Master Language="VB" CodeFile="MySite.master.vb" Inherits="MySite" %>
<%@ Register src="Controls/Menu.ascx" tagname="Menu" tagprefix="my" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">......

View 1 Replies

How To Access A User Control's Parent Form's Controls Inside The User Control's Code Behind

Jun 11, 2010

I have to access the parent form's controls inside an event handler method on my user control's code behind.

View 4 Replies

Virtual Path To Resolving The Tilde "~"?

Dec 30, 2010

Where does asp.net virtual path to resolving the tilde "~" in the links, for example <link rel="stylesheet" type="text/css" href="~/Css/Site.css" />, redirects, or "RedirectToAction" in "ASP.NET MVC".?

View 3 Replies

Custom Server Controls :: Unable To Use A Web User Control Inside Another Web User Control

Mar 10, 2011

I have a web user control that represents a simple message box. It is used to display simple messages like "Item has been deleted", or "The item was saved successfully".

On the other hand, I have another web user control that represents the item in the form of an editable form (I made this a user control because this is used in two different pages). I want to embed an instance of the message box user control inside the editable form. I am writing this right after the @Control directive:

[Code]....

Instead of using @Register directives, I register the user controls in web.config and so far this has worked just fine.

With the above markup, the project compiles, but whenever I try to navigate to a page that contains this construct, I get an HttpParseException exception. Furthermore, Visual Studio states that the tack w7rc9:MessageBox doesn't represent a known control.

What am I doing wrong?

View 2 Replies

Have The Windows User Control, Need To Convert This User Control In Web User Control?

Jul 16, 2010

I want to convert windows user control into web user control..I have the usrDataView.cs..I need to convert this file into usrdataview.ascx.can anyonr help me?...how I can convert the file...Is any method is available..

View 1 Replies

Passing Parameter From One User Control To Another User Control In An Aspx Page?

Jun 3, 2010

have two user controls on one aspx page. UC1 has a grid which contains a link button column which user clicks. Based on the value of clicked cell, I need to show some data into UC2.How do I pass data from UC1 to UC2? How do I invoke a function of UC2 from UC1?

View 2 Replies

Web Forms :: Nest / Include A User Control Inside A User Control?

Apr 16, 2010

All I would like to be able to do is include one user control within another! Is this possible? I have spent the last hour searching the internet and it seems that I can't find a single thing.

In classic ASP it would be something like:
<!--#include file="EditProject.ascx"-->

I tried this but no luck!

Parser Error Message:

There can be only one 'control' directive.

Source Error:

[Code]....

Line 1: <%@ Control Language="VB" AutoEventWireup="false" CodeFile="EditProject.ascx.vb"Line 2: Inherits="Controls_WebUserControl" %>Line 3: <form runat="server">

View 3 Replies

How To Consume Razor User Control OR MVC User Control In Layout Page

Mar 5, 2011

It's simple to create both user control from the two world : ASP.NET+Razor or MVC 3.0.But i do not known how to consume the user control FROM the razor"_layout.chtml" page.I want to put such thing within the layout page: <uc:MyTag Prop1="" Prop2="" />So i need to declare this directive at top of the layout file : <%@ Register TagPrefix="uc" TagName="MyTag" Src="Controls/Mytag.ascx" %>

View 1 Replies







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