Tuesday, January 23, 2007

ASP .Net Tips 1

I'm Going to explain now on some Control tip and tricks which will help and increase the speed of the webpages.

1.Smart navigation

Smart navigation is a little-known Internet Explorer feature that enables the individual controls on your Web forms to maintain focus between postback, as well as allows you to suppress that flicker that occurs as you load the new page.
To turn on this little-known feature, simply set the smartNavigation property of your ASPX page to True. You can also apply the property to all project pages, by adding the tag to the following location within your Web.config file


Note that smart navigation works on only Internet Explorer 5 and above; however, ASP.NET will automatically detect this and serve up the ?smart? code only if the target browser supports it.

Also, I?d personally advise that you test it against any third-party menu controls or scripts you may have running: it is prone to falling over on particularly advanced pages.

2.Stopping Your User from Right-Clicking

Want to prevent your user from performing any of the other commands available by right-clicking on a Web page in Internet Explorer? It?s not foolproof, but this neat little HTML edit usually does the trick.

Just alter the opening "body" tag of your HTML to the following:



When the menu is requested, the oncontextmenu event runs, and we instantly cancel it using JavaScript. This is especially potent as a method for stopping the user from viewing your source, when used in conjunction with a menu-less browser window. Great stuff!

3.Creating Images Dynamically

Ask any ASP developer who has ever tried to dynamically create his own images and he?ll tell you it?s a nightmare. In fact, it?s more than a nightmare. It?s practically hell. The only true solution? Reverting to an expensive, dodgy, third-party control to do the work for you.

With ASP.NET, however, you can develop your own dynamic images with ease. Simply create an image object and use the new GDI+ features to add objects to that image, such as text, rectangles, and ellipses. After that, you can simply stream straight back down to the client.

But covering the graphics features in depth would require at least another two books, and, unfortunately, we don?t have that much room. So, I?m going to share a sample that demonstrates creating a small ?Drawing? button, alongside a little blue-and-yellow bullet point.It?s the sort of personalized graphic you?ll find on sites such as Amazon.com.

Here?s the code:

Bitmap objBitmap = new Bitmap(120, 30);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.FillRectangle(new SolidBrush(Color.LightBlue), 0, 0, 120, 30);
objGraphics.FillEllipse(new SolidBrush(Color.Blue), 3, 9, 10, 10);
objGraphics.FillEllipse(new SolidBrush(Color.Yellow), 4, 10, 8, 8);
objGraphics.DrawString("Drawing", new Font("Tahoma", 8), new SolidBrush(Color.Green), 16, 8);
Response.Clear();
Response.ContentType = "image/jpeg";
objBitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
objGraphics.Dispose();
objBitmap.Dispose();

You can put it inside any event you want.

4.Clear All The Textbox Values (Reset Function)

In Classic ASP, to clear all the textboxes in a form, to start over, we just had to use a simple html 'Reset' button in the form. Sometimes that works in ASP.Net;sometimes it doesn't.

Here are a couple of ways to do this, iterating through the ASP.Net TextBox controls in a form --
Just create a Reset type subroutine - in that routine, use the following code:
in C# - it would be:

Control myForm = Page.FindControl("Form1");
foreach (Control ctl in myForm.Controls)
if(ctl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
((TextBox)ctl).Text = "";

This will clear EVERYTHING from the textboxes - even if you had them pre-populated with data. A VERY simple way to just reset it to the condition at Page_Load time, just do this in the Reset SubRoutine:

Server.Transfer("YourPageName.aspx")

5.Pressing Enter key

Sometimes, you will notice, that, in an ASP.Net form, depending on the circumstances, pressing the 'Enter' key to submit the form does not work.

To force this to happen for a particular button on your page, just put this in the Page_Load routine:

Page.RegisterHiddenField("__EVENTTARGET", "button1")

Then, change 'button1' to the ID of your particular button. Understand, of course, if your cursor is inside of a MultiLine textbox, the default action of the enter key is to create a new line in the textbox, so, if this basically works anywhere outside of that scenario.

6.ASP.Net Server Controls Not Showing on pages

It's possible that ASP.Net is not registered correctly on your system.Try running aspnet_regiis from the command prompt.

Here's the default location:

C:\WINNT\Microsoft.NET\Framework\<>\aspnet_regiis.exe -i

Windows Server 2003, you must use aspnet_regiis -i -enable. This is because of the "Web Service Extensions" feature in IIS 6

7.Where To Store Database Connection

Let's say you have a database connection (or several) that you will be using over and over. Yes, you can manually copy/type it in on every ASP.Net page - BUT - an easier way is to store it in the Web.Config file (formerly config.web) and then refer to it in the code.

In Web.Config, you would add a key to the AppSettings Section:





for OleDb - use Absolute Path - Not Server.MapPath:


Then, in your ASP.Net application - just refer to it like this:

SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings("MyDBConnection"));

source : http://www.codersource.net/asp_net_simple_tips.html

Sunday, April 23, 2006

Introduction to Windows Workstation Foundation (WF)

Consider a process like “Complain Management System”, where you need to get the customer complains through a Web site or a published for Phone no. Internal employer should be appointed to act upon complains and take the necessary actions. A Manager should review the employer actions and then get back to the customer.


Typical organization wants to implement many processors like this and monitor the progress of them.


Some elements are human processes and some are System process if you take a look at the above ( e.g Customer needs to enter the complain through a website is Human responsibility and authenticate customer in to the system is System responsibility.)


 You can find hundreds of processes like this in your day to day work environment. Do you have a facility to setup something like this using MS Office or other available software?


This is where the up coming Windows Work Flow (WF) comes in to place. WF will be an Application development framework to design applications to setup work flow in your organization and a user friendly integrated set of tools with next Office Suite (V12).


More @ http://www.codeproject.com/dotnet/UnderstandWWF.asp


Powered by Qumana


Mapping Data Provider Data Types

[.NET 2.0 Data Access]


We recommend that you use the typed accessor methods of the DataReader when you know the specific type of the value being returned. Typed accessor methods result in better performance by returning a value as a specific .NET Framework type, eliminating the need for additional type conversion. The SqlDataReader exposes SQL Server–specific typed accessor methods if a .NET Framework type does not meet the needs of the application. SQL Server–specific typed accessor methods return objects of System.Data.SqlTypes.” -- local MSDN


Above lines are extracted from MSDN which confirms that you should use accessors to read the data out of data readers and it will result better performance since it eliminates type casting. Further MSDN describes the getter names which you should use in SQL and Oracle provides for specific data type. So better to read section “Mapping Data Provider Data Types to .NET Framework Data Types” before reading values from datareaders.