Introduction to HTML and CSS

by Pascal Parent 13. May 2010 09:54

I have always believed that both designers and web developers alike should be well versed in HTML, Francois Brill has started a series aptly called “Introduction to HTML and CSS”. In part 1, he discusses the basics of HTML and processes to be a keeper.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags:

ASP.NET | General

More Linq-to-Entities – Simple create,edit, delete

by Pascal Parent 21. July 2009 16:30

I was searching the net for a simple example of a create,edit, delete with Linq-to-Entities, I eventually found but it was too elaborate, so I thought I would give my 2 cents worth and give a simple example. When I embarked on my learning mission of Linq-to-Entities it was to simplify my life, sometimes I wonder if this was the case, I still love Linq though.

Creating a new record is as easy as this:

using (DataEntities db = new DataEntities())
{
//Create a new NewsItem
var newsItem = new NewsItem();
//Assign values	
newsItem.Headline = this.txtHeadline.Text.Trim();
newsItem.PublishedDate = Convert.ToDateTime(this.txtPublishDate.Text.Trim());
newsItem.Active = this.cbActive.Checked;
newsItem.Synopsis = this.txtSynopsys.Text.Trim();
newsItem.Content = this.edContent.Text;
newsItem.Author = this.txtAuthor.Text.Trim();
//Add the new item to the set 
db.AddToNewsSet(_news);
//Commit the changes
db.SaveChanges();
}

Editing a record is slightly more complicated, first you have to have the record if it is not persisted as is the case in ASP.NET.

using (DataEntities db = new DataEntities())
{
//Get the NewsItem for editing
var newsItem = ((from NewsItem in db.NewsSet
where NewsItem.ID == newsID
select NewsItem)
.FirstOrDefault());
//Assign values	
newsItem.Headline = this.txtHeadline.Text.Trim();
newsItem.PublishedDate = Convert.ToDateTime(this.txtPublishDate.Text.Trim());
newsItem.Active = this.cbActive.Checked;
newsItem.Synopsis = this.txtSynopsys.Text.Trim();
newsItem.Content = this.edContent.Text;
newsItem.Author = this.txtAuthor.Text.Trim();
//Commit the changes
db.SaveChanges();
}

Lastly, deleting a record

using (DataEntities db = new DataEntities())
{
//Get the NewsItem for editing
var newsItem = ((from NewsItem in db.NewsSet
where NewsItem.ID == newsID
select NewsItem)
.FirstOrDefault());
//Set the record for deletion from the database
db.DeleteObject(newsItem); 
//Commit the changes
db.SaveChanges();
}

As can be seen there are no complications and Linq just does it.

In my next Linq article I will be talking about relational data editing.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: , ,

ASP.NET | Database

JQuery Validate plugin to validate a ASP.NET Form

by Pascal Parent 25. May 2009 09:30

The first time I used the JQuery Validate plugin, it did not work at all, see JQuery Validate odd behaviour with the ASP.NET Script Manager for reason, but perseverance and stubbornness prevailed and I finally created my first JQuery validated ASP.NET Forms contact form. There are a lot of examples out there, though for some odd reason I can never find a decent example of anything to do with ASP.NET Forms and JQuery, so I battled it out.

First and foremost, when using JQuery with forms the this.object.ClientID function is your second best friend, your best friend is the fact that you can have more than one CSS class descriptor in one class, for example the following CssClass="required email" is completely valid, thanks to JQuery’s CSS Selector. This means the you do not have to know the object’s name and that the same behaviour can easely be set to more than one object with ease.

But I digress, though I must be honest I am still learning a lot about JQuery’s ability to make my life easier every day.

The initiation code is simple enough:

<asp:ScriptManager ID="ScriptManagerProxy1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/Assets/Javascript/jquery.validate.pack.js" />
     Scripts>
asp:ScriptManager>
<script language="javascript" type="text/javascript">
     $(document).ready(function() {
$('.error').hide();
$('#<%= this.Page.Form.ClientID %>').validate();
});
script>

A few things worth noticing, I use the ScriptManager for relative path (the ~/ thing), this eases the problems related to maintenance and moving the ASP.NET file will cause no adverse effect, so if like me you want to refactor the path, it’s not an issue. I also hide all error text $('.error').hide() it is recommended to hide any object wit the .error Css selector prior to use. And then register the validation methods where I use this.object.ClientID to ensure that the right object is called, since I make use of MasterPages this is essential.

From here things get even easier, apply the required validation on the object

<asp:TextBox ID="txtEmail" runat="server" CssClass="required email">asp:TextBox>

Though not required, I would advise that, as a standard, the first CSS selector have an actual class in the CSS file. I also set a default class to all of my inputs.

For further built-in and custom validation requirement please head over to JQuery Validate plugin page where you will find the documentation.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: ,

ASP.NET

Weird ADO.NET Entity Framework behaviour

by Pascal Parent 17. April 2009 13:53

I started my project using a Microsoft SQL 2008 server and the ADO.NET Entity Framework only to find out that the host does not support Microsoft SQL 2008 server but only supports Microsoft SQL 2005 server.

Generally, I would just port the database and change the connection string… Which is what I did!

EF was not happy about that because EF still thought it was a SQL 2008 server and built it’s T-SQL accordingly, which failed because it used new commands. This was fine with me, until I realised to my surprise that I could not find any settings to change EF’s SQL version, I searched the code, the config files,...

A Google search did not return any valuable information either.

Though I found a solution, whether or not it is the best. Refresh the mapping file, rebuild the project and voila everything works again.

I find it odd though, I wander what would happen if I had switched to MySQL or Oracle.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Tags: , ,

ASP.NET | Database

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 The ASP.NET Guy