Saturday, January 31, 2009

Navigating a Website

Redirectig to a different webpage

protected void LoginButton_Click(object sender, EventArgs e)
{
string username = NameTextBox.Text;
Response.Redirect("~/orderpage.aspx?username=" + username);
}

Pass Information between Pages with the QueryString

protected void CheckoutButton_Click(object sender, EventArgs e)

{
string stuff = ProductTextBox.Text;
string username = Request.QueryString["username"];
string url = "~/summarypage.aspx?username=" + username + "&product=" + stuff; Response.Redirect(url);
}

Retrieving QueryString Information with Variables

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string username = Request.QueryString["username"];
WelcomeLabel.Text += ", " + username;
}
}

protected void CheckoutButton_Click(object sender, EventArgs e)
{
string stuff = ProductTextBox.Text;
string username = Request.QueryString["username"];
string url = "~/summarypage.aspx?username=" + username + "&product=" + stuff; Response.Redirect(url);
}

Using String.Format to build Proper String

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string username = Request.QueryString["username"];
string product = Request.QueryString["product"];
WelcomeLabel.Text = String.Format("Hey thanks {0}, your {1} is on its way!!!", username, product);
}
}

Friday, January 30, 2009

Command Name properties in C#

Bad Practices
When you call "Button object" by "Text" properties;

Best Practices
When you call "Button object" by "Command Name" properties;

Saturday, January 3, 2009

Assignment and Initializers

// Declare variables.
int errorCode;
string myName;

// Assign values.
errorCode = 10;
myName = "Eugene";

or

int errorCode = 10;
string myName = "Eugene";

declare a variable

// Declare an integer variable named errorCode.
int errorCode;
// Declare a string variable named myName.
string myName;

Commenting in C#

// A single-line C# comment.


/* A multiline
C# comment. */




XML-based commenting syntax

///
/// This application provides web pages
/// for my e-commerce site.
///





“IDesign C# Coding Standard”
http://www.idesign.net/