Archive for category ASP .NET
Yesterday I was working on a project which had the AJAX Extensions in use. It’s primarily a .NET 2.0 application and I had .NET Framework 3.5 SP 1 installed on my system. It was working normally and all of a sudden I got this error that: Unknown server tag ‘asp:ScriptManager’
It was strange because every thing was working and I had the reference to the AjaxControlToolkit.dll.
I found out that by adding the section below to the <system.web> node in the web.config solves the problem:-
<add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
Allows only Alphanumeric characters with a period(.), Underscore(_) and a Hyphen (-). No spaces or other characters allowed.
I’ve found this tool called The Regulator, for validating and testing the regular expressions very useful. I think some of you might find it fairly useful as well. The interface is pretty neat, very simple to use. In case you find it a bit confusing, press F1 to checkout the basics. It’s pretty much straight forward.
I’ve been having this issue with mobile development for quite sometime that I couldn’t get the mobile browser accurately by just using the Request.Browser.isMobileDevice property and I’ve found this piece of code here
Looks pretty useful.
//FIRST TRY BUILT IN ASP.NT CHECK
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVariables["HTTP_USER_AGENT"] != null)
//Create a list of all mobile types
string mobiles =
“midp”, “j2me”, “avant”, “docomo”,
“novarra”, “palmos”, “palmsource”,
“240×320″, “opwv”, “chtml”,
“pda”, “windows ce”, “mmp/”,
“blackberry”, “mib/”, “symbian”,
“wireless”, “nokia”, “hand”, “mobi”,
“phone”, “cdm”, “up.b”, “audio”,
“SIE-”, “SEC-”, “samsung”, “HTC”,
“mot-”, “mitsu”, “sagem”, “sony”
, “alcatel”, “lg”, “eric”, “vx”,
“NEC”, “philips”, “mmm”, “xx”,
“panasonic”, “sharp”, “wap”, “sch”,
“rover”, “pocket”, “benq”, “java”,
“pt”, “pg”, “vox”, “amoi”,
“bird”, “compal”, “kg”, “voda”,
“sany”, “kdd”, “dbt”, “sendo”,
“sgh”, “gradi”, “jb”, “dddi”,
//Loop through each item in the list created above
//and check if the header contains that text
foreach (string s in mobiles)
It’s simple, yet not very obvious. All you have to do is to change the normal behavior of the commas you use in the Where function to act as an OR. You’d do it like this:-
ObjES.Query.es.DefaultConjunction = esConjunction.Or;
ObjES.Query.Where(<<Go ahead with using the commas that usually defaults to an AND conjunction>>);
oh and I almost forgot to mention my colleague Bilal mentioned this to me. So special thanks to him as well.
Here’s a nice little piece of code you can use to change file attributes of a particular file, its particularly useful when you’re trying to delete a read only file.
string savedCardFilePath = “My absolute file path”; if (File.Exists(savedCardFilePath))
* Remove readonly attribute off of the file if it exists before execution
if(File.GetAttributes(savedCardFilePath) == FileAttributes.ReadOnly)
UPDATE May 14, 2012:
There have been some problems reported and better solutions given on this article so I updated the code to:
FileAttributes attributes = File.GetAttributes(file);
if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
File.SetAttributes(file, attributes ^ FileAttributes.ReadOnly);
Thanks for the feedback and sorry about the mistake
this line in both master page and content page. I removed one of them and walla! it started working.
I hope some of you folks might find this post useful some day!
You can pass multiple columns in like this:-
There is a common issue that you can’t manipulate session objects in http handlers, the files with ASHX extension Well normally you can read the contents in the session via context.Session but you can add/remove/modify that in there. So how do you do this:
The answer is simple: Just implement the IRequiresSessionState interface. It doesnt have any method to implement so you dont have to worry about any details, this just notifies the runtime that Session can be manipulated in this context. So your class declaration would look something like this:-
public class SetLabels : IHttpHandler, IRequiresSessionState