********************************************************************** Tip of the Day! Administering your SQL through Access If you wish to administer your SQL through Access, use Access Projects, rather than OBDC connections. It uses native OLEDB, and provides better performance than OBDC. ********************************************************************** Tip of the Day! Redirecting a user to another mobile page in ASP.NET To redirect a user to another mobile page in ASP.NET you should use: RedirectToMobilePage("anotherPage.aspx", true); rather than Response.Redirect, which is used on web forms. ********************************************************************** Tip of the Day! Using Response.Write to solve SQL errors If you Response.Write a problem sql string then you can determine whether your error is simply due to mistaking a variable for a string. ********************************************************************** Tip of the Day! How to fetch the recordcount when the table is bound to a DataSet To fetch the recordcount when the table is bound to a DataSet, you should use the following syntax: myDataSet.Tables("Authors").Rows.Count ********************************************************************** Tip of the Day! Using the Windows Script Host Object Model to get Registry values, when writing COM objects for ASP pages When writing COM objects for your ASP pages, a common need is to get Registry values. One of the easiest ways is to use the Windows Script Host Object Model. Set a reference under the PROJECT menu of VB to that object and then you get can get Registry information. This example gets home page info from IE: Dim WSH As New IWshRuntimeLibrary.IWshShell_Class sHomePage = WSH.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InternetExplorer\Main\Default_Page_URL") ********************************************************************** Tip of the Day! by Dan Wahlin With the introduction of ASP.NET, many Web server controls such as TextBox, DropDownList, and Label controls are now available that generate HTML for the browser and provide an object-oriented way to display and access data submitted by end users. While XSLT can still be used to generate text output from ASP.NET Web Forms, it can't be used directly to dynamically create ASP.NET Web server controls within an ASP.NET page. This is because the output of an XSLT transformation is simply a string that is passed to the client and not handled on the server by the ASP.NET infrastructure. I've seen many people attempt to create server controls using XSLT without realizing that the code is passed straight to the browser without being processed. Browsers obviously do not know how to handle code similar to the following: ********************************************************************** Tip of the Day! by ASPToday Editor HTML server controls appear very like HTML tags but have, in addition, the runat="server" attribute at the end of the HTML element. These server controls give the web developer the functionality of the Web Form's page framework, while retaining the ease of use of HTML tags, as they not only create an HTML element on a web page, but also create an instance of a server control. For example, Without the runat="server" attribute, this line of HTML would be parsed into a standard HTML button. With the runat="server" attribute, it will be parsed into an HTML server control. ********************************************************************** Tip of the Day! by S Hari The .NET Framework provides us with a tool called AL.EXE which we can use to place an assembly in shared cache on-the-fly: AL /i:mydll.dll Now your dll will be placed at the proper location by the utility. ********************************************************************** Tip of the Day! by ASPToday Editor You can check which version of Treeview WebControls you have installed by viewing the Global Assembly Cache using the Windows Explorer folder C:\Winnt (or Windows)\assembly ********************************************************************** Tip of the Day! by Mark Hoffman The easiest way to copy files into the resource directory on SharePoint is to map a drive to the Web Storage System by running the following line from a command prompt: subst m: \\.\backofficestorage This will map drive M to the Web Storage System. If your workspace was called "workspace1", then you would navigate to: M:\localhost\SharePoint Portal Server\workspaces\workspace1\portal\resources ********************************************************************** Tip of the Day! by ASPToday Editor In Visual Studio.NET you can compile a component class by simply right-clicking on the project in the Solution Explorer. If you are writing the class by hand in a text file, you can compile it as follows: vbc /t:library /r:System.dll /r:System.Web.dll MyComponent.vb The /t:library parameter indicated that you want to create a DLL instead of an EXE. The /r parameters specify any dependent assemblies you use. ********************************************************************** Tip of the Day! by Ian Vink To see if an XML element exists, set a Node equal to it then see if that Node "Is Nothing": Set xmlNode = xmldoc.selectSingleNode("SomeNodeName") If Not xmlNode Is Nothing Then 'Do something with the node data End If ********************************************************************** Tip of the Day! by ASPToday Editor A command allows us to define a function for the data source to perform. Using a connection, we execute a command against the data source which may, or may not, return results. Commands have a CommandText property that defined the command action, which might be a SQL statement. The CommandText is interpreted based on the CommandType set for the command. If the command type is "StoredProcedure" then the command text is interpreted as the name of a stored procedure. If the type is "Text" then it is interpreted as a direct command. In order for a command to be executed, it must be associated with a connection that is open at the time the command is executed. ********************************************************************** Tip of the Day! by ASPToday Editor Cookies are only sent to the server with requests for pages that are within the same virtual path as that set in the cookie, i.e. the value of "path" and any pages within (or below) this virtual path. The default, if a value for the "path" is not specifically set in the cookie, is the virtual path of the page where the cookie we created. To have a cookie sent to all pages in a site, we just use Path = " / ". ********************************************************************** Tip of the Day! by ASPToday Editor A neat way of handling connection strings is to use the appSettings section of web.config: ********************************************************************** Tip of the Day! by Editor ASPToday This simple snippet allows you to delete files on your hard drive from an ASP.NET page. <%@ Page Language="VB" debug="true" %> <%@ Import Namespace="System.IO" %> <% File.Delete("C:\file.txt") Dim f As FileInfo f = New FileInfo("C:\file.txt") f.Delete() %> If you attempt to delete a file that does not exist, no exceptions are thrown unless part of the path does not exist, in which case a DirectoryNotFoundException is thrown. ********************************************************************** Tip of the Day! by Editor ASPToday The following snippet will delete a directory. <%@ Page Language="VB" debug="true" %> <%@ Import Namespace="System.IO" %> <% Directory.Delete("C:\Create") Dim dir As DirectoryInfo dir= New DirectoryInfo("C:\Create") dir.Delete() %> If you attempt to delete a non-existent directory, a DirectoryNotFound exception will be thrown. ********************************************************************** Tip of the Day! by S Hari Here is a simple way to find out whether a given EXE file is managed or not in a .NET Environment 1. Run the ILDASM utility with the EXE name as a parameter, for example, ILDASM test.exe 2. If the file is not managed, ILDASM will display the message, "test.exe has no valid CLR header and cannot be disassembled." 3. If the file is managed, the ILDASM tool will run successfully. ********************************************************************** Tip of the Day! by Ajoy Krishnamoorthy To validate a phone number, add a textbox control to accept the phone number, then, add a regularexpressionvalidator control to validate the phone number textbox. You then specify the rules in the validationexpression property as shown below: validphone.aspx --------------------
Telephone (000) 000-0000
********************************************************************** Tip of the Day! by ASPToday Editor When building an interactive form using classic ASP, a common technique is to use some client-side script with certain controls (e.g. listbox and checkbox) to automatically submit the
they reside on to the server for processing when the user selects a value. This allows the server to update the page in response to changes the user makes in the form. In ASP.NET, certain Web form server controls (TextBox, CheckBox, RadioButton) provide a property named AutoPostBack. If we set this property to TRUE for a control, that control will automatically post its value, and the values of the rest of the controls on a form, back to the server when the user selects a value. ********************************************************************** Tip of the Day! by Ian Vink If you need to see client side what the XML data looks like in your XML Document server side and don't wish to write it to the browser, add this piece of code in your client side VBScript: MSGBOX "<%=xmlDocument.XML%>" ********************************************************************** Tip of the Day! by Sandra Gopikrishna A User Control can contain client script, HTML elements, ASP.NET code and other server controls. Here is a simple user control that outputs HTML when the page is rendered: footer.ascx ---------------------
This table is in a User Control
Page Created on: <%= Now() %>
asptoday.aspx --------------------- <%@ Register tagprefix="asptoday" Tagname="footer" Src="footer.ascx" %> ********************************************************************** Tip of the Day! by Sandra Gopikrishna The following snippet shows a method of how to do a simple Replace() in a string by employing the Regex object of ASP.NET: replace.aspx ------------ <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Text.RegularExpressions" %> Original Text:
Replaced Text: When this example is run, the string "Welcome to ASPToday." is converted to "Goodbye from ASPToday." and displayed on the screen. ********************************************************************** Tip of the Day! by Ajoy Krishnamoorthy An update or insert call to the database with the data containing a single quote could result in an error. To avoid this, use the VBScript "replace" method to replace the single quote with two single quotes. Eg: strSQL="insert into table_name values(NAME='"&replace(request("NAME"),"'","''")&"', "&request("DoB")&")" In the above example if the value of the name field contains a single quote it will be replaced with two single quotes. ********************************************************************** Tip of the Day! by JS Greenwood To determine whether ASP script is executing on a live or development server, or whether it is being executed by a developer or end user, you can check the HTTP_HOST Server-Variable, and see if it is "Localhost". If it is, then we can assume that the system is being used for development purposes. ********************************************************************** Tip of the Day! by Editor ASPToday When using classes such as StreamWriter to populate a memory stream, the stream's Length property will not be accurate until the stream writer's Flush method is called (because of the buffering it performs). ********************************************************************** Tip of the Day! by Editor ASPToday C# is the only one of the supplied .NET langauages that supports operator overloading. This works in the same way as method overloading, but for operators. The reason for this is to allow the standard operators to be used on objects such as classes. ********************************************************************** Tip of the Day! by Editor ASPToday If you're a Visual Basic or VBScript programmer trying out C# for the first time, then there's one really important thing to note: C# is case sensitive. ********************************************************************** Tip of the Day! by ASPToday Reader Today's tip has been supplied by ASPToday reader, Tom Le Blanc: If you have a problem with your ASP code that only manifests itself on the production server, here is a tip for tracing the problem without burdening your users too much. In the development environment with classic ASP you would likely use Response.Write to output a SQL string, or series of outputs you expect of your code. You can do the some thing on your production server, but this time bracket the output in HTML comments: Response.Write('' & VbCrLf) This way, you can use View Source to see the outputs, but your users won't notice your tracing activity on the face of the page. ********************************************************************** Tip of the Day! by ASPToday Reader Today's tip has been supplied by ASPToday Reader Neil Rudd: If you use Microsoft Visual Interdev 6 and code Javascript, you will know that Visual Interdev does not recognise *.js files. There is a way to alter Visual Interdev so it can. ** Please note this tip involves altering the system registery settings and should not be attempted unless you know what you are doing. Please also note that I have only done this on a Windows 98 SE machine, I have not tried this on any other OS. ** 1. Open the registry (regedit.exe) and locate the "VisualStudio" key under HKEY_LOCAL_MACHINE/Software/Microsoft 2. Within this key "VisualStudio/6.0" open "Editors". 3. You should see 3 sub keys. Locate the Key that contains the extensions HTML, HTM, ASP etc. 3. Within this key create a new DWORD Value with the name js and assign a hexadecimal value data of 28 4. Close the registery and restart Visual Interdev. 5. Now, if you open any js files and include // ********************************************************************** Tip of the Day! by Srinivasa Sivakumar How to find the Operating System version information from ASP.NET: <%@ Import Namespace="System" %> ********************************************************************** Tip of the Day! by Sandra Gopikrishna In VB.NET we can retrive the command line arguments passed to the application on-the-fly by employing the 'GetCommandLineArgs' method of the Environment class: retcommand.vb ------------- Imports System Imports System.Threading Namespace cmdparam Module cmdparam Public Sub Main() Dim args As String() args = Environment.GetCommandLineArgs() If (args.Length <> 3 ) Then Console.WriteLine("The program accepts only 2 parameters") Exit Sub End If Console.WriteLine("The value of first argument is : " + args(1)) Console.WriteLine("The value of second argument is : " + args(2)) End Sub End Module End Namespace compiling the above file ----------------------- vbc retcommand.vb running the file ----------------- retcommand.exe param1 param2 ********************************************************************** Tip of the Day! by Sandra Gopikrishna A Proper Case String (sometimes known as Title Case) is one that is lowercase, but the first character of every word is in uppercase. The following Tip demonstrates a method of converting the supplied string into Proper Case by using the StrConv native method of ASP.NET: propercas.aspx --------------- <%@ Page Language="VB" %> **********************************************************************