Sunday, June 8, 2008

Asp .Net Introduction : Notepad way

Let's explore Asp .Net with notepad. By doing so one will get acquainted with the Asp .Net tags which is imperative in working with Asp.Net Ajax; templated controls like Repeater, DataList, ListView, etc.

Lets start with creating a new Website.
Open notepad and type the following.









Here we are creating a form tag and inside that an asp .net button. runat = server denotes that the tag is getting executed in web server and not in the browser as is the case with html. pages.

Save the file in the newly created project folder with .aspx extension. Take Visual Studio right click the project in solution explorer and select refresh folder.
Run the project with the newly added aspx file selected.

You will get the follwing output.















TextBox

Now we will see textbox edit the previously created file so that it looks as follows.
Here we are adding a Label and a text box.















Here is the output.














Events

Open the first example ie. the Button Example in notepad. Add a script section inside the portion. Here the difference is that it is having a runat = "server" attribute as well as language = "C#".

The event handler should follow a certain signature comprising of Object and EventArgs.

Later on you wire up the event handler to the button using OnClick.



















Here is the output.















ListBox

ListBox
control is used to display multi items.
Each item in a listbox is a .



















Output













CheckBoxList : Displaying the selected Items







protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem li in CheckBoxList1.Items)
if (li.Selected == true)
Response.Write(li.ToString() + " ");
}


Calendar Showing Selected Dates

Setting the SelectionMode of Calendar to DayWeek as shown below enables week wise selection of dates. (I am omiting the angle brackets)







protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
SelectedDatesCollection std = Calendar1.SelectedDates;
foreach (DateTime d in std)
{
Response.Write(d.ToString("D"));


}
}



VB .Net

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim sd As SelectedDatesCollection = Calendar1.SelectedDates
For Each dt As DateTime In sd
Response.Write(dt.ToString("D") + "
")
Next
End Sub












{
SelectedDatesCollection se = Calendar1.SelectedDates;
foreach (DateTime dt in se)
{
Response.Write(dt.ToString("D") );
Response.Write(dt.Month.ToString());
Response.Write(dt.Day.ToString() );

Response.Write(dt.Year.ToString());
}
}

1 comment:

  1. This blog could be more exciting if you can create another topic that everyone can relate on.

    ReplyDelete