This post contains attachments v20020304235156.zip 
Summary
In this article I designed an application, which gives you the output for your selected/entered input string. Basically, this application shows how your given input string is handled by various string methods like ToLower, ToUpper, Split, StartsWith, EndsWith, IndexOf, LastIndexOf.
In this article, I will explain how various concepts of ASP.NET programming were implemented in the designed application.
It covers how you can
separate code from the presentation content
use server controls in the web page
write the class where it can be implemented as component
control the page events
attach events to the controls/objects
write the same application in languages like VB.Net and C#.Net
Separation of code from presentation content
It is good idea to have code separated from presentation content. With this kind of strategy, you can design and develop components easily and efficiently.
In my application, I separated the code by creating StringTest.cs and StringTest.vb files.
If you look at the code in stringtest.aspx, I am inheriting the code in Page directive as follows:
In C# language:
<%@ Page Language=c# Src=StringTest.cs Inherits=PanduTest.StringTest%>
In VB language:
<%@ Page Language=VB Src=StringTest.vb Inherits=PanduTest.StringTest%>
Here PanduTest is the namespace and StringTest is the class name.
When you call PanduTest.StringTest, the class constructor gets called.
In C#, the following function is being invoked.
public StringTest()
{
Page.Init += new System.EventHandler(Page_Init);
}
In VB,
Public Sub New()
AddHandler Page.Init, AddressOf Page_Init
End Sub
Here Page_Init is being fired in the class constructor. In this constructor, I attached Page Init event.
In InitializeComponent function, I attached event handlers to Page Load, Button Click, DropDownList SelectChange Events as follows:
In VB,
Private Sub InitializeComponent
AddHandler Page.Load, AddressOf Page_Load
AddHandler cmdShow.Click, AddressOf cmdShow_Click
AddHandler dlStringFun.SelectedIndexChanged, AddressOf dlStringFun_OnSelectedIndex
End Sub
In C#,
private void InitializeComponent()
{
Page.Load += new System.EventHandler(this.Page_Load);
cmdShow.Click += new System.EventHandler(cmdShow_Click);
dlStringFun.SelectedIndexChanged += new System.EventHandler ( dlStringFun_OnSelectedIndex);
}
I implemented server controls like Label, DropDownList, TextBox, TableRow, TableCell, Table elements. Please see source code file “stringtest.aspxâ€, which gives you clear idea, how to implement these server side controls.
When the user selects the option in the DropDownList, TextBox(s) will be displayed dynamically and the label text will change accordingly.
In C#,
private void dlStringFun_OnSelectedIndex(Object sender, EventArgs e)
{
.......
}
In VB,
Private Sub dlStringFun_OnSelectedIndex(ByVal sender As Object, ByVal e As EventArgs)
.......
End Sub
The above function handles the DropDownList SelectedIndex event.
When you click the Show Button, the System.String methods will be applied to the given input string(s) and the message will be displayed at the bottom of the button.
I tested this application successfully with .Net SDK Beta 1 version on Windows 2000 OS.
By using this kind of programming approach, you can implement the concept in various applications. If you have any questions, please do feel free to contact me.
| Further additional information | |
Updating comments...
Updating comments...
|