Thursday, July 29, 2010

Reverse a string




<%
sometext = "Hello Everyone!"
response.write(strReverse(sometext))
%>





output>>>>
!enoyrevE olleH

Create an array




<%
Dim famname(5),i
famname(0) = "Jan Egil"
famname(1) = "Tove"
famname(2) = "Hege"
famname(3) = "Stale"
famname(4) = "Kai Jim"
famname(5) = "Borge"

For i = 0 to 5
      response.write(famname(i) & "
")
Next
%>




output>>>
Jan Egil
Tove
Hege
Stale
Kai Jim
Borge

Looping through HTML headers

html>


<%
dim i
for i=1 to 6
   response.write("Heading " & i & "")
next
%>




output is>>

Date and time

<%@ language="javascript" %>


<%
var d=new Date()
var h=d.getHours()

Response.Write("")
Response.Write(d)
Response.Write("
")
if (h<12)
   {
   Response.Write("Good Morning!")
   }
else
   {
   Response.Write("Good day!")
   }
%>



output is>>>>

Wed Jul 28 22:47:47 EDT 2010
Good day!

Format text with HTML tags



<%
response.write("

You can use HTML tags to format the text!

")
%>


<%
response.write("
This text is styled with the style attribute!
")
%>



output is>>>
This text is styled with the style attribute!

Write text using ASP




<%
response.write("Hello World!")
%>


Sunday, July 18, 2010

Sending Email from Gmail

protected void btnSendEmail_Click(object sender, EventArgs e)
{
//Create Mail Message Object with content that you want to send with mail.System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage("dotnetguts@gmail.com","myfriend@yahoo.com",
"This is the mail subject", "Just wanted to say Hello");

MyMailMessage.IsBodyHtml = false;

//Proper Authentication Details need to be passed when sending email from gmail
System.Net.NetworkCredential mailAuthentication = new
System.Net.NetworkCredential("dotnetguts@gmail.com", "myPassword");

//Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
//For different server like yahoo this details changes and you can
//get it from respective server.
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com",587);

//Enable SSLmailClient.EnableSsl = true;

mailClient.UseDefaultCredentials = false;

mailClient.Credentials = mailAuthentication;

mailClient.Send(MyMailMessage);
}

Insert data from gridview to database (ASP.NET)

using System;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
foreach (GridViewRow row in gvTest.Rows)
{
CheckBox box = row.FindControl("cbChecked") as CheckBox;
}
}
protected void btnCGo_Click(object sender, EventArgs e)
{
// Never give a button click event any more responsibility that capturing the click event :)
GetInformationToSave();
}

///
/// Gets the information to save.
///

protected void GetInformationToSave()
{
foreach (GridViewRow row in gvTest.Rows)
{//This condition is added since here we are inserting only the rows which are checked
CheckBox checkbox = (CheckBox)row.FindControl("cbChecked");

// Collect your information below if the checkbox is checked...
if (checkbox.Checked)
{
Label lblFirstName = (Label)row.FindControl("lblFirstName");
Label lblLastName= (Label)row.FindControl("lblLastName");

//After all your information, send to method that is responsible for saving data to databasea
SaveToDatabase(lblFirstName.Text.Trim(), lblLastName.Text.Trim());
}
}
}

///
/// Saves to database.
///

///
The first name.
/// The last name.
protected void SaveToDatabase(string firstName, string lastName)
{
// CODE HERE TO SAVE TO DATABASE. OBVIOUSLY THIS METHOD SHOULD NOT BE IN THE PAGE CODE BEHIND BUT JUST HERE
// TO DEMONSTRATE.
}
}

Thursday, July 15, 2010

ASP.NET 2.0 Features

If you have worked with ASP.NET 1.x versions, you will undoubtedly agree that it was a great product
that provided huge improvements in the way web applications were designed and deployed. If
ASP.NET 1.x was a great product, then what’s wrong with it? Well, nothing, actually, but when developing
software, there is always a trade-off between how much can be done, how many resources you
have, and how much time you have to do it. There is an almost never-ending supply of features you
can add, but at some stage you have to ship the product. You cannot doubt that ASP.NET 1.0 shipped
with an impressive array of features, but the ASP.NET team members are ambitious, and they not only
had plans of their own but also listened to their users. ASP.NET 2.0 addresses the areas that both the
development team and users wanted to improve. The aims of the new version are: