I expected to type \n into the ConfirmText property of the AJAX Control Toolkit’s ConfirmButtonExtender and get a new line.
This doesn’t work, but you can use this character code:
Specifically, ampersand pound ten semicolon.
I expected to type \n into the ConfirmText property of the AJAX Control Toolkit’s ConfirmButtonExtender and get a new line.
This doesn’t work, but you can use this character code:
Specifically, ampersand pound ten semicolon.
Controls inside an ASP.NET UpdatePanel cannot be bound to jQuery events after a partial postback. Here are some tips using pageLoad():
There have been many articles and forums addressing the fact that the MaxLength property of the ASP.NET TextBox does not work when you set TextMode to MultiLine. The majority of these solutions use the KeyPress and OnBlur events. This brings with it lots of JavaScript and a host of browser issues. I was impressed by the RegularExpressionValidator options because they can tie in to the AJAX ValidatorCalloutExtender. I also like the server-side validation that you get with the native validation controls.
The solution I settled on is a combination of all the above. I use an ASP.NET RegularExpressionValidator on the MultiLine TextBox. The code looks like this:
<asp:TextBox runat="server" ID="txtDescription" TextMode="MultiLine" Rows="5" Width="300" />
<asp:RegularExpressionValidator runat="server" ID="revtxtDescription" ControlToValidate="txtDescription" ErrorMessage="Exceeds 500 character maximum." ValidationExpression="^[\s\S]{0,500}$" Display="None" />
<ajax:ValidatorCalloutExtender ID="vcerevtxtDescription" runat="server" TargetControlID="revtxtDescription" />
Good so far, but to quote Mark Hildreth:
“I agree that that works for preventing users from posting too much text, however it does’t prevent them from typing more than 500 characters into the box. The validators only perform their validation in the onchange event which is not triggered on every key stroke. Imagine your dismay if you spent 10 minutes typing into a textbox, only to have the form say you have exceeded the 500 character limit?”
The JavaScript below will call this RegularExpressionValidator every second. I find that it does not noticeably slow down the form.
<script type="text/javascript">
$(document).ready(function () {
setInterval("validateDescription();", 1000);
});
function validateDescription() {
var myValidator = document.getElementById("<%= revtxtDescription.ClientID %>");
ValidatorValidate(myValidator);
}
</script>
Now as the user is typing, they will be warned within one second of exceeding 500 characters. If they paste into the textbox, it will alert them too.
I was looking for a way to filter child entities with eager loading. I ran into this useful blog post by Beth Massi on the subject.
Here is the code I ended up using. It doesn’t work with server-side paging, but I didn’t need it in this case.
Dim query = (From x In db.OrderChecklistItems Where x.Enabled = True Select OCI = x, _
OD = From y In x.OrderDocuments Where y.OrderID = OrderID)Dim customers = From item In query.ToList Select item.OCI
GridView1.DataSource = customers
I found it tricky to get actual entities in the GridView RowDataBound event.
Per Diego Vega’s post here, this may only happen because I am using the EntitySetName property of the EntityDataSource.
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
Dim descriptor As ComponentModel.ICustomTypeDescriptor = e.Row.DataItem
If descriptor IsNot Nothing Then
Dim prop = descriptor.GetProperties().Cast(Of ComponentModel.PropertyDescriptor)().First()
Dim Order As Order = DirectCast(descriptor.GetPropertyOwner(prop), Order)
Response.Write(“Order Number:” & Order.OrderNumber)
End If
End If
End Sub
I ran across this post on Stack Overflow. Here is the code I ended up using:
Dim count = (From x In db.Orders Where x.OrderID = orderID From y In x.OrderDetails Select y).Count
To save a password hash to an XML file, you can call this function:
FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text & "|" & txtUsername.Text, "SHA1")
You can see my attempt at a password salt by simply apppending the Username.
Sometimes I want to show the e.Row.RowIndex of a GridViewRow in the markup of the page. I don’t want to hook into the RowDataBound method just to display a simple number. The answer varies for GridViews and Repeaters. Click here for the complete rundown.
GridView:
<asp:Literal runat="server" Text='<%# Container.DataItemIndex + 1 %>' />
Repeater:
<asp:Literal runat="server" Text='<%# Container.ItemIndex + 1 %>' />
Data Access Practices Using Microsoft .Net: A Nerdly Comparison
In this article a comparison of these options:
– Connected Data Access with ADO.NET
– Disconnected Data Access with ADO.NET and Typed DataSets
– Basic Object Relation Mapping with LINQ to SQL
– Object Relational Mapping with LINQ to Entities and the Entity Framework
See also: Extending NerdDinner: Exploring Different Database Options
I was having some troubles with large ViewStates, so I found this article. It does an excellent job of explaining the inner workings of ViewState, and some of the common ways to misuse it.
http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx
– Zachary