ASP.NET

 

Spring 2006

 

ASP.NET RegularExpressionValidator – Samantha

 

If you want to validate a control to only contain letters and blank spaces, set the “ValidationExpression” property to “[a-zA-Z ]{1,30}” (without the quotes).

 

Note:  There is a blank space after Z.  If you do not want the control to accept any spaces, just delete the space after Z.  “{1,30}” means that there must be at least 1 and at most 30 characters in the control.  Modify the numbers accordingly.

 

Confirming Deletes in an ASP.NET Datagrid - Samantha

 

This website will show you how to get a confirmation popup/messagebox to show when the "Delete" button is clicked.

http://www.dotnetbips.com/articles/displayarticle.aspx?id=108

 

ASP.NET Datagrid Error – Samantha

 

If you are working with ASP.NET and datagrids and get an error like this:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Make sure you have a value for the “DataKeyField” property on the datagrid.

 

ASP.NET RequiredFieldValidator in Datagrid    Samantha

 

If you have RequiredFieldValidators in the footer of a datagrid that is, for example, supposed to validate information before you click the “Add” button (which is also in the footer) and the RequiredFieldValidators do not work then you need to set the “CausesValidation” property to “True” on the “Add” button.

 

Note:  You might need to set, for example, navigational buttons or other buttons’ “CausesValidation” property to “False”.

 

Example datagrid footer:

 

 

 

ASP.NET Default Button    Samantha

 

If you have a button on your page that needs to fire when the “Enter” key is pressed, use this VB code in the Page_Load procedure:

 

TextBox1.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+Button1.UniqueID+"').click();return false;}} else {return true}; ")

 

Note: If you have several textboxes on your page, either set this code up for each textbox or for the very last textbox.

 

If you are using ASP.NET 2.0, you can set the “defaultbutton” value of the “<form>” to the button you want to fire when the “Enter” key is pressed.

 

Example: <form id="form1" defaultbutton="Button1" defaultfocus="TextBox1" runat="server">