Wednesday, October 17, 2012

Integrating Client-Side JavaScript with ASP.NET

While ASP.NET performs most of its processing on the server, some actions are better served by client-side processing.

http://msdn.microsoft.com/asp.net/using/building/web/default.aspx?pull=/library/en-us/dnaspp/html/ClientSideScript.asp

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com

Manage Concurrency in MVC application using Entity Framework


Why Need Concurrency
Consider a case when there are two users A and B working one same record; User A opens a record to update it. He started modifying some data. But before he completes and saves updated data another user B opens the record edit it and updates the record. In this case both users get success message but as user A has updated the record lastly so his changes will preserve but the changes done by user B will get lost. This case may be acceptable for some applications but in some applications even a single change is crucial and we should handle such case very carefully.



Optimistic Concurrency (From Wiki)

Optimistic concurrency control (OCC) is a concurrency control method that assumes that multiple transactions can complete without affecting each other, and that therefore transactions can proceed without locking the data resources that they affect. Before committing, each transaction verifies that no other transaction has modified its data. If the check reveals conflicting modifications, the committing transaction rolls back.



Entity Framework provides support for optimistic concurrency model, It means when we use EF to save data in database there are no locks held on database (It has advantage of performance) but before data saved it checks in weather data from the database has been changes since it is read; if it is same then save operation completes and If it is changed it throws exception. Let us see how to use concurrency of EF in MVC application Every column in the EF table has concurrency property as show below Step 1 Create MVC 3 application. (it is assumed that you know how to create MVC 3 application) Step 2 Create Database ; While creating database table add column with name TimeStamp and data type as timestamp . Value in column with data type timestamp is updated every time a row containing a timestamp column is inserted or updated. Step 3 add ADO.NET Entity Model to the solution; After adding EF edmx file above table appears as below Step 4 Change the Concurrency Mode to Fixed; StoreGeneratedPatteren to Computed; Type to Binary; Concurrency Mode can have any of following value None : It is default value; it means this property is not involved in any concurrency check (This mean its value is not checked before save data in database for changes since it is read). Fixed: it means its original value is checked for changes since it is read for concurrency check. This is done using WHERE clause. Step 5 Create controller , view for list, add, and edit mode. (It is assumed that you know how to create view and controller in MVC, One quick way to create default view and controller is right click Controller folder and click Add.. - > Controller) Step 6 In Edit view for the Employee add following hidden control. @Html.HiddenFor(model => model.TimeStamp) This step is required for MVC application ; Whenever we read the record/entity for edit view we get the value stored in TimeStamp field and we store it in the hidden field; So that when user click submit button TimeStamp value goes in Model along with other updated values. This passed value is automatically included by EF in Where clause as we have set the Concurrency Mode to Fixed. We are done with the application now Let us test it. Run the application and Go to Employee Edit screen; Do some changes and before pressing the save button open other instance of a browser and open same employee in Edit screen and do some changes and save it. Now go to first browser window and click save button it will throw an exception as "OptimisitcConcurrencyException was unhandled by user code" This caused OptimisticConcurrencyException ; This is because when we saved in second browser instance the value of TimeStamp field is changes to some other value (as timestamp field get updated on each update and insert) and when we clicked Save on first browser it sent old TimeStamp value in where clause and they didn’t match.

Wednesday, July 15, 2009

Creating a Side by Side application on IIS 6

Preparation for Demo

1. Create a Site in Visual Studio 2003
Add a page to the site which prints out the .NET Version (System.Environment.Version)
2. Create a Site in Visual Studio 2003
Add a page to the site which prints out the .NET Version (System.Environment.Version)

Start of Demo

3. Show the sites briefly, pages and what they do.

Show .NET 1.0 Code running under .NET 1.1

4. Show the Sites set up in IIS
5. Ensure the Sites are running under .NET 1.1
This proves that .NET code built under .NET 1.0 can run under 1.1.
6. Run the page from both sites showing the same framework version printing out.

Run Side by Side

7. Change the .NET 1.1 site to run under .NET 2.0

8. Show the .NET 1.1 Site running
9. Show the .NET 1.0 Site running
This will fail with a “Sever Unavailable” message
Show the Event Log entry under “Application” events.
10. Explain that sites running under different versions of the framework must be isolated into their own application pools.

Run Side by Side without Errors

11. Create two application pools called “ASP.NET 1.1 Applications” and “ASP.NET 2.0 Applications”
12. Place the .NET 1.1 Application into the “ASP.NET 2.0 Applications” pool.
13. Place the .NET 1.0 Application into the “ASP.NET 1.1 Applications” pool.
14. Show both sites running side by side at the same time.

Tuesday, September 06, 2005

DropDownList Controls In an ASP.Net DataGrid

This article will demonstrate how to add a DropDownList control to each row of an ASP.Net DataGrid, including the header row. The article demonstrates how to perform data binding on each DropDownList control, and how to handle events when the DropDownList selection changes.
In this article we will demonstrate how to add a data bound, event raising control into a column of an ASP.Net DataGrid. We will also see how to place a control into the header row of a DataGrid. We will demonstrate this using the DropDownList control.
The following screen shot shows a web form in design mode. We are going to query the authors table in SQL Server’s pubs table. You can see we have one column (au_fname) to display the au_fname column from the table. In the second column we have added DropDownList controls to both the header line, and in each row with a data record.

Let’s first take a look at the ASPX markup to create the grid.
id="DataGrid1" runat="server"
AutoGenerateColumns="False"
OnItemDataBound="DataGrid1_ItemDataBound">




ID="HeaderDropDown" Runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />


ID="ItemDropDown" Runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="DropDown_SelectedIndexChanged" />




We have a DropDownList in the header declared as HeaderDropDown, and a DropDownList in the Item template declared as ItemDropDown. Notice we set the AutoPostBack property to true. Setting AutoPostBack to true allows the form to post back to the server and raise an event each time the user changes a selection in the DropDownList control. We also assign an event handler for the SelectedIndexChanged event. Notice we are sharing the same event handler (DropDown_SelectedIndexChanged) for all DropDownList controls. We will see later in the code how we can still identity the exact control firing the event.
Before we look at the SelectedIndexChanged event handlers, let’s think about populating the drop down controls with data for the user to select. When the DataGrid binds to a data source it will create a DropDownList control to place in the header row, and also a DropDownList for each row of data rendered. We need to catch when ASP.NET creates these controls so we can populate them with data for the user to select from. The best place to do this is during the ItemDataBound event. You can see in the ASPX above we are handling this event using the DataGrid1_ItemDataBound method, shown below.
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.AlternatingItem
e.Item.ItemType == ListItemType.Item)
{
string[] options = { "Option1", "Option2", "Option3" };
DropDownList list = (DropDownList)e.Item.FindControl("ItemDropDown");
list.DataSource = options;
list.DataBind();
}
else if(e.Item.ItemType == ListItemType.Header)
{
string[] options = { "OptionA", "OptionB", "OptionC" };
DropDownList list = (DropDownList)e.Item.FindControl("HeaderDropDown");
list.DataSource = options;
list.DataBind();
}
}
ItemDataBound occurs after a DataGridItem is bound to the grid. The event fires for each row, including the header and the footer rows. We know if the item belongs to the header, the footer, or one of the items by checking the Item.ItemType property of the event. Rows of data will always have a ListItemType of Item or AlternatingItem.
We use the FindControl method to obtain a reference to the DropDownList control for each row. To learn more about using FindControl in these scenarios, see ‘In Search Of ASP.NET Controls’. We specify the control to find by name. For the header remember we specified a name of “HeaderDropDown”, while rows with data will have a name of “ItemDropDown”.
We have an array of strings to represent data for the DropDownList control to bind against. Note that this event will fire for each row of the grid, so you’ll want to make sure this method performs well. You would not want to perform a database query each time the event fires. In this example, the DropDownList control in the header binds against a different set of strings than the DropDownList controls in the item rows.
Whenever the user modifies any of the DropDownList selections in our grid, the DropDown_SelectedIndexChanged event will fire. Remember, we assigned the same event handler for all of our lists, and we set the AutoPostBack property to true so a new selection should post back to the server and raise the event immediately. The event handler is shown below.
protected void DropDown_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList list = (DropDownList)sender;
TableCell cell = list.Parent as TableCell;
DataGridItem item = cell.Parent as DataGridItem;
int index = item.ItemIndex;
string content = item.Cells[0].Text;
Response.Write(
String.Format("Row {0} contains {1}", index, content)
);

}
First, notice the sender parameter will be the DropDownList control modified by the user. By casting the object reference to a DropDownList we get a reference to the modified control and can see what the user has selected.
Secondly, notice the DropDownList control’s parent will be a TableCell of the grid. The parent of the TableCell will be a DataGridItem. Once we have a reference to the DataGridItem, we can see which row was selected by using the ItemIndex property. (Note: ItemIndex will be -1 for the header row). With the DataGridItem we can also inspect the values of other cells in the row.

Once you know the control invoking the event you can find almost any other piece of information you need about the grid or the underlying data source by getting to the DataGridItem object and inspecting the ItemIndex property or the collection of TableCells. With this information in hand, adding controls to the rows of your DataGrid should become a straightforward process.

Event Bubbling From Web User Controls in ASP.NET (C#)

This C# code example demonstrates event bubbling from a web user control (ASCX) to a parent page (ASPX) and the shows the flow of events through execution.
Some user controls are entirely self contained, for example, a user control displaying current stock quotes does not need to interact with any other content on the page. Other user controls will contain buttons to post back. Although it is possible to subscribe to the button click event from the containing page, doing so would break some of the object oriented rules of encapsulation. A better idea is to publish an event in the user control to allow any interested parties to handle the event.

This technique is commonly referred to as “event bubbling” since the event can continue to pass through layers, starting at the bottom (the user control) and perhaps reaching the top level (the page) like a bubble moving up a champagne glass.

For starters, let’s create a user control with a button attached.

WebUserControl1

The code behind for the user control looks like the following.

public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Panel Panel1;

private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Page_Load
");
}

private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("WebUserControl1 :: Begin Button1_Click
");
OnBubbleClick(e);
Response.Write("WebUserControl1 :: End Button1_Click
");
}

public event EventHandler BubbleClick;

protected void OnBubbleClick(EventArgs e)
{
if(BubbleClick != null)
{
BubbleClick(this, e);
}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

}


The user control specifies a public event (BubbleClick) which declares a delegate. Anyone interested in the BubbleClick event can add an EventHandler method to execute when the event fires – just like the user control adds an EventHandler for when the Button fires the Click event.

In the OnBubbleClick event, we first check to see if anyone has attached to the event (BubbleClick != null), we can then invoke all the event handling methods by calling BubbleClick, passing through the EventArgs parameter and setting the user control (this) as the event sender. Notice we are also using Response.Write to follow the flow of execution.

An ASPX page can now put the user control to work.
In the code behind for the page.


public class WebForm1 : System.Web.UI.Page
{
protected WebUserControl1 BubbleControl;

private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("WebForm1 :: Page_Load
");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
BubbleControl.BubbleClick += new EventHandler(WebForm1_BubbleClick);
}
#endregion

private void WebForm1_BubbleClick(object sender, EventArgs e)
{
Response.Write("WebForm1 :: WebForm1_BubbleClick from " +
sender.GetType().ToString() + "
");
}
}


Notice the parent page simply needs to add an event handler during InitializeComponent method. When we receive the event we will again use Reponse.Write to follow the flow of execution. When the page executes after clicking on the user control button, you should see the following.




One word of warning: if at anytime events mysteriously stop work, check the InitializeComponent method to make sure the designer has not removed any of the code adding event handlers.


Additional Resources
MSDN: Events and Delegates
MSDN: Raising An Event

Monday, July 25, 2005

How to Distribute ASP.NET Application

Find out more details on how to distribute ASP.NET applications and
components from development and test servers to production servers.


Deployment is the process of distributing a
completed application or component to be installed on other computers.
Microsoft® ASP.NET is designed to make Web application deployment
easy.




Explains how to distribute all files associated
with your ASP.NET application to a production server.




Explains how to compile and distribute component
assemblies to your ASP.NET application's \Bin directory.




Explains the global assembly cache and how to
distribute shared component assemblies to it.




Explains how to distribute compiled assemblies
that contain classes that implement the IHttpHandler and IHttpModule
interfaces. This includes required configuration settings for including new
HTTP handlers and HTTP modules in your application.



Regards,
Mitesh V. Mehta
Email : miteshvmehta@gmail.com




Tuesday, April 05, 2005

Formatting ASP.NET DataGrid's Data

Question:

The data in database is as follows:
Id Name Color HireDate
1 Tom Pink 9/15/2001 3:30:00 AM
2 Jerry Blue 9/15/1991 3:30:00 AM

Question:

* How change DataGrid row color according to color in database .
* Format of the Date should be mm/dd/yyyy

Solution:

Step 1:

In webform1.aspx drag drop a Datagrid.




Simple binding of theData to datagrid as given below

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub

Sub BindData()
Dim ds As New DataSet()
Dim sqlStmt As String = "SELECT * FROM ColorTable"
Dim conString As String = "server=localhost;database=Northwind;uid=sa;pwd=;"
Dim myda As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString)
myda.Fill(ds, "Table")
Dim dv As New DataView(ds.Tables(0))
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub

Step 2:

To display the data in the Datagrid based on Database values

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
'Create a DataView Based on the DataSource of DataGrid
Dim dv As DataView = DataGrid1.DataSource
Dim dc As DataColumnCollection = dv.Table.Columns

'Check for ItemType
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

'Declare string variable
'Assign the relevant data to a variable
Dim fieldcolor As String
fieldcolor = DataBinder.Eval(e.Item.DataItem, "color")

'To convert the value of Type String to System.Drawing.Color
e.Item.BackColor = System.Drawing.Color.FromName(fieldcolor)


'Declare DateTime variable
'Assign the relevant data to a variable
'To display DateTime field in the format "MM/dd/yyyy"
Dim fieldDate As DateTime
fieldDate = Convert.ToDateTime _
(DataBinder.Eval(e.Item.DataItem, "HireDate", "{0:MM/dd/yyyy}"))
'To display the value in the proper cell of DataGrid
e.Item.Cells(dc.IndexOf(dc("HireDate"))).Text = fieldDate
End If

End Sub



The other ways to format Date in MM/dd/yyyy format are:

a)

e.Item.Cells(dc.IndexOf(dc("HireDate"))).Text = fieldDate.ToString("d")

b)

e.Item.Cells(dc.IndexOf(dc("HireDate"))).Text = fieldDate.ToShortDateString()

Pivot Tables with ADO.NET and Display in Horizontal Paged DataGrid

This article describes a simple method to pivot a DataTable producing rows for each column and a column for each row. The pivoted DataTable is then displayed in a DataGrid using horizontal paging to view a limited number of Columns in each page. This is a common display technique used to compare, for instance, product features, where the product names appear across the top of the DataGrid with the Features listed down the side.

http://aspalliance.com/538

ASP.NET Sample application with source code

Duwamish 7.0 is a multitier, distributed business-to-consumer commerce application built specifically for the Microsoft® .NET platform.

You can download the installation file with source code at

VB App : http://download.microsoft.com/download/visualstudio.netenta/smpDCS/7.0/NT5XP/EN-US/Duwamish7-CS.cab

C# App: http://download.microsoft.com/download/visualstudio.netenta/smpDVB/7.0/NT5XP/EN-US/Duwamish7-VB.cab

With Best Regards,
Mitesh V. Mehta

Resolving quick time-out issue with Forms Authentication

When using forms authentication with slidingExpiration set to true (default), the cookie is updated only when more than half the timeout value has elapsed. As a result of this, you might be logged off sooner than you think.

Consider this: You have set the timeout to 30 minutes. You logon on at 3:00 pm; a FormsAuthenticationTicket is set to expire at 3:30 pm. The expiration of this ticket will not be extended for another 30 minutes until you make a request after 3:15 pm. So, if you made your last request at 3:15 pm, the ticket will still expire at 3:30 pm as more than half the timeout value has not elapsed (giving you a 15 minute window before you get logged out).

On the other had, if you had made a request at 3:16 pm, the expiration of the ticket is extended to 3:46 p.m.

From MSDN:

timeout : Specifies the amount of time, in integer minutes, after which the cookie expires. The default value is 30. If the SlidingExpiration attribute is true, the timeout attribute is a sliding value, expiring at the specified number of minutes after the time the last request was received. To prevent compromised performance, and to avoid multiple browser warnings for users that have cookie warnings turned on, the cookie is updated when more than half the specified time has elapsed. This might result in a loss of precision. Persistent cookies do not time out.

For reference visit : http://msdn.microsoft.com/library/defaultasp?url=/library/en-us/cpgenref/html/gngrfforms.asp


With Best Regards,
Mitesh Mehta

Trick with DataGrid

You can trick the DataGrid's ButtonColumn to use an image for a button without having to use a TemplateColumn. It's really easy. In the DataGrid Property Builder, change the column's Button Type to “LinkButton”, then use regular HTML for the “Text” property, like




Click “Apply“, you now have an image button without the hassle of having a TemplateColumn. Switch over to the ASPX code view, and you should see the following:

ASP.NET SQL Server Session state - Links and Overview

Basic steps to set up SQL Server Session state
1. Run either of these scripts (InstallSqlState uses temp tables, InstallPersistSqlState uses permanent tables so it survives reboots)
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\InstallSqlState.sql
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\InstallPersistSqlState.sql

2. Change your session state mode in web.config to SQLServer:
mode="SQLServer"
sqlConnectionString="data source=server;user id=uid;password=pwd"
cookieless="false" timeout="20" />

References
Good overview http://idunno.org/dotNet/sessionState.aspx

MSDN overview of SQL Server Session State
http://support.microsoft.com/default.aspx?kbid=311209

Common issues
325056 PRB: Session State Is Lost in Web Farm If You Use SqlServer or
http://support.microsoft.com/?id=325056
323744 FIX: "The View State Is Invalid for This Page and Might Be Corrupted"
http://support.microsoft.com/?id=323744


With Best Regards,
Mitesh V. Mehta

Overriding Pop up Blocker Settings in IE

The new Popup Blocker feature of Internet Explorer 6.0 provided in Windows XP SP2 is really good one. Even though it helps in blocking useless windows while browing on internet, sometimes it block useful windows initiated by trusted webpages also. I used to get really frustrated when emptying Hotmail or Yahoo Junk Mail folders as it used to block the confirmation window.
You can set Temporarily Allow Pop ups but its really irritating at times. Also you can set the Always Allows Pop up From This Site, but what if u dont want to switch that on and decide at run time?
Yes there is a way to overcome this by holding Cntrl Key, If you want the popup window to appear then press Control Key--> Hold it and then --> Click the URL you wish to... thats it:), it overrides the popup blocker settings and allows you to see the intended window initiated by the URL.

Regards,
Mitesh V. Mehta

Wednesday, March 16, 2005

Playing Flash Files in ASP.NET

Copy the HTML code below and paste it into your HTML

codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
WIDTH="550" HEIGHT="400" id="myMovieName">

NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash"
PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">



1. Change the HEIGHT and WIDTH parameters to match the height and width of the movie dimensions or use percentage values, if desired.
2. Change "moviename.swf" where it appears in the OBJECT and EMBED tags to the name of movie to be played.

Sending mail

You can use the System.Web.Mail.MailMessage and the System.Web.Mail.SmtpMail class to send e-mail in your ASPX pages. Below is a simple example of using this class to send mail

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>


Mail Test






TIP#1 : ASP.NET

Generally when using Forms authentication in ASP.NET you are able to secure your .aspx pages but you have not secured Images or documents like Ms-Word, Excel etc. A quick tip to secure these items is that you can configure that these extensions should be served by asp.net and not IIS.

1. In your IIS , Right click on the Virtual Directory and select Properties.
2. On Configuration Ta, a dialog box appears with the list of file extensions.
3. Click Add and Enter the extension type in the textbox such as .doc .ppt etc.
4. Point your path to aspnet_isapi.dll found under %windir%\Microsoft.NET\Framework\v1.1.4322 5. In "Limit to" radio button and put the same properties as like for aspx files i.e. GET, POST etc.

Its Done!

Enjoy!!

Pagination in ASP.Net DataGrid

Quick steps to work out pagination in your datagrid.. Go to your data grid
properties... Set AllowPaging property to true... Set the PageSize to your
desired page size... Now go to events section in the properties... You have
to override PageIndexChanged Event... In the event handler... Write code
similar to the one below:

private void dgdImages_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
//Change the current page index to the new one
dgdImages.CurrentPageIndex = e.NewPageIndex;
//Update your data if required
dgdImages.DataSource = CreateDataSource();
//bind the data again
dgdImages.DataBind();
}

That's it... Your datagrid does not need to make your page long scrollable
now... Do note though that if you change the data in the background and the
new data does not contain as many pages as your current page index now you
might land up getting exceptions... So make sure that you do the necessary
work there...

Mitesh Mehta

Dr. Dotnetsky's Cool .NET Tips & Tricks

Nice tips & tricks on .Net...a regular must read which doesn't
restrict only on langauge but speaks about even on DB's, Operating
systems, SDK's, various Service packs etc etc

More enjoyment here...
http://www.eggheadcafe.com/articles/20040821.asp

ASP.NET Vulnerability

This is today's HOT NEWS for ASP.NET developers!

There is a report on ASP.NET vulnerability and Microsoft is currently investigating on this issue. The issue is that ASP.NET is failing to perform proper canonicalization of some URLs.

This issue affects Web content owners who are running any version of ASP.NET on Microsoft Windows 2000, Windows 2000 Server, Windows XP Professional, and Windows Server 2003.

To know more about this issue and recommended guidance on best practices visit

http://www.microsoft.com/security/incident/aspnet.mspx

Saturday, October 23, 2004

Default Button for a TextBox (Data entry screen) in ASP.NET

Sometimes I get annoyed when hitting the enter key in a TextBox (say login screen) resulting in undesired effects like the wrong Button being “clicked“. After so many code tricks, I found the below method that allows you to specify a default Button to submit when the user hits the enter key in a TextBox.

When you press a key on your keyboard, the js OnKeyPress event is fired. This calls a function to which we pass the id of the button associated with the TextBox. The function gets a reference to the button and simuilates a mouse-click on the Button. We perform a browser detection because IE and Netscape have different event models. The function finally returns false so that the keypress event is cancelled (otherwise a second form submit will be raised). I tried this code with newer versions of IE 6.0/Netscape 7 it worked great!.

//client side js
function clickButton(e, buttonid){
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
if (event.keyCode == 13){
bt.click();
return false;
}
}
}
}

//code behind
TextBox1.Attributes.Add("onkeypress", "return clickButton(event,'" + Button1.ClientID + "')");

The code behind generates the following code:

< input name="TextBox1" type="text" id="TextBox1" onkeypress="return clickButton(event,'Button1')" / >

This causes web control Button1 to be clicked when the enter key is hit inside TextBox1.



With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Adding Cross-Site Scripting Protection to ASP.NET 1.0

ASP.NET 1.1 added the ValidateRequest attribute to protect your site from cross-site scripting. What do you do, however, if your Web site is still running ASP.NET 1.0? This article shows how you can add similar functionality to your ASP.NET 1.0 Web sites.

Check out the article @
http://msdn.microsoft.com/library/en-us/dnaspp/html/ScriptingProtection.asp

With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Multilingual Support in .NET

This is a Web Solution designed to teach all newcomers into the .Net field on how to incorporate Multi-language support into your Web Applications. You have to download the accompaning ZIP file.
This tutorial will teach you

- How to create the Resource files for various languages.
- How to access the Resource file data from the web pages.
- How to store Unicode (multilingual) data into the database.
- How to access multilingual data from the database.

You can find the tutorial article at http://www.developersdex.com/gurus/articles/500.asp?Page=1


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/

Better Ways to Manage Your Cache in ASP.NET

Caching is one of the features in ASP.NET 1.x that most developers are familiar with. And it has helped to fuel a yearning for cache dependency in SQL Server. The ability to refresh the cache if a row in a table has been modified is very useful to a lot of developers. And hence in ASP.NET 2.0, Microsoft built SQL Server cache dependency right into the product.

Read more here http://www.devx.com/asp/Article/21751/1954?pf=true


With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/