Say you have a GridView control with a CheckBox column embedded. When the check box is checked, it fires an event. How can you find out the index of the corresponding row that contains the check box? Here is the code snippet: VB.NET code: Protected Sub chkSelect_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim cb As CheckBox = CType(sender, CheckBox) Dim gr As GridViewRow = CType(cb.NamingContainer, GridViewRow) If (gr IsNot Nothing) Then Dim i […]
ASP.NET
1. Create a subfolder of App_Code folder named VBCode, and another subfolder named CSCode. 2. Change web.config file as follows: <compilation debug=”false”> <codeSubDirectories> <add directoryName=”VBCode” /> <add directoryName=”CSCode” /> </codeSubDirectories> </compilation> Reference: http://msdn.microsoft.com/en-us/library/t990ks23(vs.80).aspx
I came across a question asking how to change browser’s window status information when user moves the mouse over a button on an ASP.NET web page. The solution is to use JavaScript.In the Page_Load event handler, add the following two lines of code: Button1.Attributes.Add(“OnMouseMove”, “javascript:window.status=’Message’;”) Button1.Attributes.Add(“OnMouseOut”, “javascript:window.status=’Done’;) Note, the solution only works in Internet Explorer. FireFox by default disables the ability to change the status bar, because the status bar has been abused by spammers.
I came across to a post by Anil John talking about how to enforce password complexity by using regular expresion. Here is the regular expression he wrote: ^.*(?=.{10,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$ What it enforces is: Must be at least 10 characters Must contain at least one one lower case letter, one upper case letter, one digit and one special character Valid special characters are – @#$%^&+= This regular expression can be easily used for the RegularExpressValidator control in ASP.NET, and […]
If you are a Windows Server Administrator and notice an ASP.NET web application is malfunctioning, then how will you stop this application? Answer: Just delete the application from the server. Just kidding. 🙂 Real answer: Open up the web.config file of the web application, then change httpRuntime to false. Like this: <system.web> <httpRuntime enabled=”false” /> </system.web> Don’t forget to save the change. The modification of web.config will cause the application to restart, but because httpRuntime […]
For Windows applications, it might be a good idea to use the EventLog to log application errors because the EventLog is very powerful yet very simple to use. However, it might not be a good idea to use it to log ASP.NET web application errors. Why? There are several reasons: It’s all about security. In the malicious cyber world, the security of the web application is a very big concern of any company, if not […]
The membership provider is a new feature in ASP.NET 2.0 and helps web developers quickly and easily implement forms authentication and authorization in their web applications. But what if you can’t use the membership provider in your applications? For example, my company implements a single sign-on system for authentication (many companies have the similar single sign-on system), and the user who is accessing our web application is redirected to the single sign-on page for authentication. […]
Today, one of my web sites went down and the application sent me an exception error message like “SHUTDOWN is in progress. Login failed for user ‘…’. Only administrators may connect at this time.” It worried me at first because I thought my web site was under some malicious attack caused the server to shut down. So I searched the Internet with the error message and it turned out that it had nothing to do […]
One of our applications started giving an error this morning like this: The remote server returned an error: (503) Server Unavailable. The stack trace shows that the application was trying to parse a template in XML format and encountered an error on the DTD file. When the line of DOCTYPE was commented out, the error went away and the application came back running. Here is the DOCTYPE of the application: <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML […]
If you use the TableAdapter Configuration Wizard in Visual Studio 2005 to create a strong-typed dataset (as described in Scott Mitchell’s ASP.NET 2.0 Data Access Tutorial – Creating a Data Access Layer), you will be asked if you would like to save the database connection string in the configuration file. If you choose to save it, it will be placed in the <connectionStrings> section. But what if you want to change the name of the […]