asp.net detect master file location change - asp.net

I moved the ASP.NET master files to a different directory using the Solution Explorer.
Is there a way to propagate this change to the .aspx pages so that the MasterPageFile references get updated automatically?
(This leads me to another question - if I change the namespace or name of a class is there a way to automatically update this change in all files that use this class?)
Thanks.

To avoid renaming file path, you can just set maser page in web.configs.
<pages theme="Default" masterPageFile="~/Defaut.master">
...
</pages>
Creating Master Page (MasterPage in Web.config)

Related

asp.net application getting master page name from appSettings key

I'm trying to figure out how an asp.net application is setting the MasterPageFile from a config file appSettings key like this:
<appSettings>
<add key="MasterPageFile" value="~/Other.Master" >
</appSettings>
This causes it to ignore the Page directive's MasterPageFile attribute in the .aspx files (which point to a different master page). I have searched through the whole solution and can't find any ConfigurationManager or MasterPageFile calls that are loading this appSettings key. From what I understand, you would usually have to put this in a system.web section of a config file in a pages element with a masterPageFile attribute.
Anyway, how is it setting the master page from this appSettings key? Is there some other way to retrieve appSettings that I don't know about?
MaserPage File can be set at page level or pre_init level. Setting it at config level will override your page settings so avoid it.

App_theme not adding styles to web page

I have a web site project that uses an App_theme folder for styles. When I run the site the styles are not applied to the site. What is going on?
It works on other developers computers, but they are using a local IIS 7 server whereas I am using the built in Visual Studio IIS. Note - the site is setup using a web site project (not application).
Maybe the problem is in incorrect folder name - ~/App_Themes instead of yours App_theme?
Right click on your website -> Add ASP.NET Folder -> App_Themes; this will add theme folder automatically, and then you will be able to add themes there.
To apply a theme to a WebSite, it is necessary to set the element to the name of the theme, either a global theme or a page theme, as shown in the following example:
<configuration>
<system.web>
<pages theme="ThemeName" />
</system.web>
</configuration>
How to: Apply ASP.NET Themes
make sure the top of the page includes the "theme" attribute, here's an example of the default page
<%# Page Language="C#" ClientIDMode="Static" Title="Reset Sessions" MasterPageFile="~/site.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="WorkbenchWeb.resetsession" Theme="Theme" StyleSheetTheme="Theme" %>
Theme is there, i check Init event and theme is in web.config for all pages, however for some reason css under App_Themes are not added to one of the pages. However, for other pages it's ok - added automatically.

CSS in App_Theme folder gets Cached in Browser

The Stylesheet in the App_Theme folder gets cached in the browser. What should be the approach? so that whenever there is a new deployment the browser should take the latest stylesheets and not the one cached in the browser.
This was happening for other css(which are not in theme folder) too, so used custom control as mentioned in the link
http://blog.sallarp.com/asp-net-automatic-css-javascript-versioning/
How this could be done for the CSS in the Theme folder?
Edit: The theme name is mentioned in the web.config as mentioned below. so its not just the html link tag which I had solved by using the method mentioned in the link.
<pages styleSheetTheme="Default">
<controls>
</controls>
</pages>
I too have come across this and the solution I came up with is to add a version to your CSS filename, not pretty but without disabling cache on IIS I could think of no other way.
Rename the CSS file to say
mycss-V1.0.css, which will force your
user's web browsers to reload the CSS
When deploying the web application, include the version number in the themes path. For example, App_Themes/Default/v1.2.0.4321/, where v1.2.0.4321 is the folder added at deployment for version 1.2.0.4321. This preserves both the theme name (e.g., "Default") and the file names, which makes source code control and path references much easier. ASP.NET loads all of the CSS files in the current theme folder regardless of subfolders. This not only solves the problem referencing CSS files, but images that are referenced from within the CSS files (e.g., background-image).
Additionally, the browser cache duration for App_Themes may be increased to improve performance while ensuring that the next time the web application is updated, all the theme files will be updated.
Add this to the <configuration> section of the Web.Config to have the browsers cache for 120 days.
<location path="App_Themes">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="120.00:00:00" />
</staticContent>
</system.webServer>
</location>
You could timestamp the css file name or use htaccess to setup caching limits as discussed here http://css-tricks.com/can-we-prevent-css-caching/
may be send the time stamp as a get parameter as well.
EG:
http://mysite.com/theme/dir/style.css?id=24033957203712
where 24033957203712 is the time stamp.
The browser cache is based on the expiration time set in the response header or browser setting.
There are timing when we are deploying CSS and wish to push them to the user immediately, but are unable to version the css file as referenced from asp file (such as style.css?v2).
In these cases, we can add the changed/new style classes in the particular CSS file alone to the Head section of the aspx file. It will not create any style overrides and fix the issue.

How to load webusercontrol from classlibrary

I have a classlibrary. This library contains widget.ascx control. How to load this webusercontrol from web. I know "LoadControl". But this not applicable.
How can i load web usercontrol from library?
2009.09.24
My main goal is i'm creating addon based web application. Every addon will be widget of web application.
I need dynamically load web usercontrol from library
You need to add a reference of the library to your web project.
Then instantiate it as you would with any other control, either programatically or in an #Register directive.
Kindness,
Dan
In addition to obviously adding the DLL to your project references, you also need to register the control. You can do this on each page that will use the control, but I usually prefer to do it in web.config. As a quick example, here's the line I used to register the Infragistics UltraWebGrid control in my app.
<pages>
<controls>
<add tagPrefix="ig" namespace="Infragistics.WebUI.UltraWebGrid" assembly="Infragistics35.WebUI.UltraWebGrid.v8.2, Version=8.2.20082.1000, Culture=neutral, PublicKeyToken=7DD5C3163F2CD0CB"/>
</controls>
</pages>
TagPrefix works kind of like an in-page namespace, so if I had a bunch of controls I was importing from one DLL, they'd probably all have the same TagPrefix. In the page, I'd simply reference my control as follows:
<ig:UltraWebGrid runat="server" SetSomeOtherPropertiesToo="blah" />
I am not sure how the .ascx file is added to your class library. Normally user controls are loaded using LoadControl which requires an existing file. In case the user control is compiled as embedded resource in your class library you could use GetManifestResourceStream() to read the user controls' contents and then ParseControl to create a control from the string read using GetManifestResourceStream.

VB webform in IronPython asp.net website

I tried to bring a previously done webform made in vb.net to an IronPython asp.net website with no luck. After seeing it didnt work, I tried to write the simplest codebehind vb.net webform to see if there was a problem with vb.net in an IronPython website and I got the following usual error
"be sure that the defined class in this file matchs with the one in the attribute inherits and that it extends the right base page (page or control)" (sorry if the translation isnt the most accurate I get that message in spanish)
but if I create a vb.net webform in the same website, with the sourcecode in the same file (with the vb.net code between script runat="server" tags in the same page) I get no problem.
Do I have to configure something for both kind of sourcecode languages to run in such way in the same IronPython website, like configuring something in the webconfig file or is there some compatibility issue for doing that which can't be resolved?
The code between <script /> tags is compiled dynamically when the page is first run. This enables you to mix languages. However, the classes in your code-behind files are statically compiled into an assembly by VS.NET ... and a VS.NET project can only support one language at a time.
One solution is to put your VB.NET code-behinds in a separate assembly. For example:
Add a new VB Class Library project to your existing solution
Add a reference to System.Web
Create your VB.NET code-behinds. They should be normal classes inheriting from System.Web.UI.Page.
In your ASP.NET website project, add a reference to the new project
Edit the # Page directives in your *.aspx files to inherit the classes in the new project
e.g. <%# Page Inherits="YourNewVBClassLibraryProject.MyVBCodeBehinds" ... /> where the Inherits attribute contains the relevant namespace-qualified class name
Thanks for the reply Serilla. Your information was interesting but I simply solved it by creating the app_folder and adding the vb files there. Do you think I could have some future problem for doing so?
The problem with the vb files was when these lines in the web.config were enabled for Ironpython to work
<pages compilationMode="Auto" pageParserFilterType="Microsoft.Web.Scripting.UI.NoCompileCodePageParserFilter" pageBaseType="Microsoft.Web.Scripting.UI.ScriptPage" userControlBaseType="Microsoft.Web.Scripting.UI.ScriptUserControl">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
when I removed them, vb code behind files worked but ironpython didnt. When the lines were there, Ironpython code behind files worked but vb ones didnt

Resources