Archive for category ASP .NET
Unknown server tag ‘asp:ScriptManager’ After having AjaxControlToolkit.dll referenced
Posted by Imran Akram in ASP .NET, Web Development on July 24, 2009
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:-
<pages>
<controls>
<add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />
</controls>
</pages>
Useful Regular Expression for a UserName
Posted by Imran Akram in ASP .NET, Web Development on May 17, 2009
^[a-zA-Z0-9_\.\-]+$
Allows only Alphanumeric characters with a period(.), Underscore(_) and a Hyphen (-). No spaces or other characters allowed.
Regular Expression Testing Tool, The Regulator
Posted by Imran Akram in ASP .NET, Web Development on May 15, 2009
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.
How to detect a mobile browser in ASP.NET
Posted by Imran Akram in ASP .NET, Web Development on March 31, 2009
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.
public static bool isMobileBrowser()
{
//GETS THE CURRENT USER CONTEXT
HttpContext context = HttpContext.Current;
//FIRST TRY BUILT IN ASP.NT CHECK
if (context.Request.Browser.IsMobileDevice)
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVariables["HTTP_X_WAP_PROFILE"] != null)
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVariables["HTTP_ACCEPT"] != null &&
context.Request.ServerVariables["HTTP_ACCEPT"].ToLower().Contains(“wap”))
{
return true;
}
//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 =
new[]
{
“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”,
“moto”, “iphone”
};
//Loop through each item in the list created above
//and check if the header contains that text
foreach (string s in mobiles)
{
if (context.Request.ServerVariables["HTTP_USER_AGENT"].
ToLower().Contains(s.ToLower()))
{
return true;
}
}
}
return false;
}
How to use an OR in a query in EntitySpaces?
Posted by Imran Akram in ASP .NET, C#, Web Development on March 25, 2009
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.
How to remove ReadOnly Attribute from a file?
Posted by Imran Akram in ASP .NET, C#, Web Development on January 15, 2009
Hello friends,
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)
File.SetAttributes(savedCardFilePath, FileAttributes.Normal);
File.Delete(savedCardFilePath);
}
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
TinyMCE not working on IE 7
Posted by Imran Akram in ASP .NET, Web Development on January 1, 2009
Happy new year folks, 09′ started off for me with a very strange bug. I was working on a form and decided to use TinyMCE in it for multi-line text editing and it was working A-OK in FF3, Chrome and Safari but not on IE 7. God that was a real pain in the butt going through all the javascript and I had absolutely no idea what was happening. It turned out that I had
<script language=”javascript” type=”text/javascript” src=”../tinymce/jscripts/tiny_mce/tiny_mce.js”></script>
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!
Cheers.
How to use OrderBy() for multiple columns in EntitySpaces?
Posted by Imran Akram in ASP .NET, C#, VB .NET, Web Development on December 31, 2008
You can pass multiple columns in like this:-
collection.Query.OrderBy(collection.Query.ProductID.Descending, collection.Query.CategoryID.Ascending)
How to manipulate Session in Http Handlers
Posted by Imran Akram in ASP .NET, C#, VB .NET, Web Development on December 26, 2008
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
{
…