Thursday, June 26, 2008

My .Net Videos in Youtube/Google videos

Asp .Net Ajax Videos
Asp.Net Ajax II : TextBoxWatermarkExtender
Asp .Net Ajax III : ConfirmButtonExender
Asp .Net Ajax III : SliderExtender
Asp .Net Ajax V : MaskEditExtender






Asp .Net 2.0 Membership Vidoes
Asp.Net 2.0 Membership I : LoginStatus LoginName
ASP.Net 2.0 Membership II : LoginView Control
ASP.Net 2.0 Membership III - CreateUserWizard
ASP.Net 2.0 Membership IV Roles
aspnet_regsql : Adding Membership tables to Sql Server
WPF
WPF I : Button - Shalvin
Asp .net State Management
Asp .Net Query String
ASP.Net (VB.Net) Session Variable ArrayList
Asp .Net Profile



Asp .Net Controls
Asp.Net I : Introduction and Button Control
ASP.Net Controls - II : TextBox
Asp.Net III : ListBox Inline Page Mode IsPostBack
Asp.Net IV : Label AssociateControlId AccessKey
Implementing Date Selection Functionality using Multiple Combo Boxes
C#
String.Format
C# Error Handling - Shalvin P D
VB .Net
VB.Net 2008 Controls III :ListBox
VB .Net 2008 Controls V : NumericUpDown
VB .Net 2008 Controls VI : Simple Calculator

Google Videos
Creating Window Service in C#
C# (Windows Forms) MultiThreading


WPF Creating Class C#
Ado .Net
Introduction to Ado .Net
Ado .Net ExecuteScalar
Asp .Net
Displaying DataReader Contents in a RadioButtonList

Asp.Net (VB.Net) DropDownList DataTextField DataValueField

Asp.Net (VB.Net) Displaying DataReader contents in a RadioButtonList

ASP.Net DataList HyperLink with Wizard
FileUpload Control
Asp.Net C# DataSet GridView

ASP.Net (C#) Tracing

Asp .Net 2.0 Membership videos
ASP.Net Membership Authentication, Authorization and Role based security
Asp.Net 2.0 Membership V Denying Anonymous users
Asp.Net 2.0 Membership VIII Protecting a folder












C# Windows Forms
PrintDocument and PrintPreview Control

Gdi+
I : DrawString DrawLine
II : FillRectangle FillEllipse
III : Custom Pen
IV : HatchBrush
V: Color.FromArgb
VI :ScreenSaver : Random Class and Timer Control

VII : Working with Bitmaps

Gdi+ (ASP.Net) XII : Bitmap DrawString

Multithreading and Miscellaneous
Multithreading in Windows Forms
Code Access Security

Compression and Decompression in .Net
Win32 Api Visual Basic 6 : SwapMouseButton
Reflection in .Net : Displaying all properties, methods and events of a type


Xml
XmlDocument in VB .Net

Extracting xml from Sql Server tables

Sql Server
Sql Server 2005 : Creating Tables and Relationships (Sql)
Sql Server WHERE Clause and Stored Procedures
Web Service
Creating and consuming Web Service
Web Parts
Asp .Net Web Parts : Design Mode and Brose Mode

Saturday, June 21, 2008

Creating Asp .Net Custom Controls

Custom Controls are reusable dlls.
Start out by creating a class library in C#. Add reference to System.Web. We are overriding the Render method of System.Web.UI.Control class and using HtmlTextWriterClass we are outputing Text to the browser.

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

namespace HelloCustomCtl
{
 public class HelloCtl : Control 
 {
  protected override void Render(HtmlTextWriter writer)
  {
   writer.Write("Shalvin");
  }
 }
}

Build the project.

Testing the Custom Control

Start ASP .Net, preferably add a new tab to the toolbox. Right click the tab and select Choose Item. Click on the browse button navigate to the bin folder of previously created class library and select the dll.
Now the control will appear in the toolbox and you can use it in your project.

WebControl With Properties
Since WebControl class provides the properties, methods, and events that are common to all Web server controls, this control eventually will have a set of common properties found in common controls.
Along the way we are implementing two properties Text and Location that can be set from propeties window while using the control.

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

public class MultiTdCtl : WebControl
{

private string mText;
public string Text
{
get { return mText ; }
set { mText = value; }
}

private string mLocation;
public string Location
{
get
{
return mLocation;
}
set
{
mLocation = value;
}
}

protected override void RenderContents(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Border, "1");
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(mText); writer.RenderEndTag ();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.WriteLine(mLocation);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
}
}

With C# 3.0 the lengthy getter and setter code is not required in fact you replace the code with the following :

public string Text
{
get;
set;
}
public string Location
{
get;
set;
}

..writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.Write(Text); writer.RenderEndTag ();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
writer.WriteLine(Location);

Creating Composite Control

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

namespace CompositeCtl
{
public class CompositeCtl : CompositeControl
{
    Label lbl;
    TextBox txt;

   protected override void CreateChildControls()
    {
        lbl = new Label { Text = "Name" };
        this.Controls.Add(lbl);


        txt = new TextBox();
        this.Controls.Add(txt);
    }
}
}
Composite Control 2
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CompositeCtlEg
{
   public class ShalvinCompositeCtl : CompositeControl
    {
       Label lbl, lblMessage;
       TextBox txt;
        Button btn;
        protected override void CreateChildControls()
        {
            lblMessage = new Label { Text = "" };
            this.Controls.Add(lblMessage);
            lbl = new Label { Text = "Name" };
            this.Controls.Add(lbl);

            txt = new TextBox();
            this.Controls.Add(txt);

            btn = new Button { Text = "Shalvin" };
            btn.Click +=new EventHandler(btn_Click);
            this.Controls.Add(btn);
        }

        void btn_Click(object sender, EventArgs e)
        {
            lblMessage.Text = "Hello " + txt.Text;
        }

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
           
            writer.RenderBeginTag(HtmlTextWriterTag.Table);

            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.AddAttribute(HtmlTextWriterAttribute.Colspan, "2");
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
           lblMessage.RenderControl(writer);
            writer.RenderEndTag();
            writer.RenderEndTag();

            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            lbl.RenderControl(writer);
            writer.RenderEndTag();
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            txt.RenderControl(writer);
            writer.RenderEndTag();
            writer.RenderEndTag();

            writer.RenderBeginTag(HtmlTextWriterTag.Tr);
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            btn.RenderControl(writer);
            writer.RenderEndTag();
            writer.RenderEndTag();
            
            writer.RenderEndTag();
        }
    }
}

Wednesday, June 18, 2008

Session Asp .Net : Storing DataSet

This blog is an add on to my youtube vide ASP.Net (VB.Net) Session Variable ArrayList - Shalvin
Session state allows values to be stored in one page and accessed through out the site. Session state allows complex data to be stored whereas Query String supports only string value.
The session data is stored in the memory of Web Server.

Asp .Net uses an unique 120 bit identifier for tracking sessions. This ID is the only piece of information that is transmitted between the web server and the client. When the client presents the session ID, ASP.NET looks up the corresponding session, retrieves the serialized data from the state server, converts it to live objects, and places these objects into a special collection so they can be accessed in code. This process takes place automatically.
It is possible to store large amounts of data in a Session Variable. In this example I am constructing a dataset and assigning the contents to a Session variable and passing the showing the data of session variable on another page.

This example makes use of appSettings section of web.config to store connectionstring information. If you are not familiar with appSettings visit my blog Web.config's appSettings section to avoid hard coded memory variable

//web.config




//Default.aspx


using System.Configuration;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
 SqlConnection cnn;
 SqlDataAdapter da;
 DataSet ds = new DataSet();
 protected void Page_Load(object sender, EventArgs e)
 {
  cnn = new SqlConnection(ConfigurationManager.AppSettings.Get	("Cnn"));
cnn.Open(); da = new SqlDataAdapter("select ProductName, UnitPrice from Products", cnn); da.Fill(ds, "Prod");
Session["Prod"] = ds.Tables["Prod"];
} protected void btnShowCart_Click(object sender, EventArgs e) { Response.Redirect("ShoppingCart.aspx");
} }

protected void Page_Load(object sender, EventArgs e)
{
 GridView1.DataSource = (DataTable)Session["Prod"];
 DataBind();
}

Related Blogs
Query String Asp .Net : Working with multiple values

ASP.Net 2.0 Profile

Query String Asp .Net : Working with multiple values

Query string is the part of URL that can be used to send data as parameters. Let's first analyze the query string generated by Google on making a search for 'Shalvin'

http://www.google.co.in/search?hl=en&q=Shalvin.Here two values are passed as query string.

Create a Web site with two web pages.
In the button click of Default.aspx write the following code:

protected void sumButton_Click(object sender, EventArgs e)
{ Response.Redirect("Sum.aspx?Val1=" + txtVal1.Text + "&Val2=" + txtVal2.Text); }

Here is the code for extracting the value in the second page.
protected void Page_Load(object sender, EventArgs e)
{
	Response.Write("Hello " + Request.QueryString["Name"] + " your blog is " + Request.QueryString["Blog"]);
}
 Calculator

<body>
    <form id="form1" runat="server">
    <div>
    
        Value 1<asp:TextBox ID="txtVal1" runat="server"></asp:TextBox>
        <asp:CompareValidator ID="CompareValidator1" runat="server" 
            ControlToValidate="txtVal1" ErrorMessage="Value cannot be string" 
            Operator="DataTypeCheck" Type="Integer"></asp:CompareValidator>
        <br />
        <br />
        Value 2<asp:TextBox ID="txtVal2" runat="server"></asp:TextBox>
        <asp:CompareValidator ID="CompareValidator2" runat="server" 
            ControlToValidate="txtVal2" ErrorMessage="Value cannot be string " 
            Operator="DataTypeCheck" Type="Integer"></asp:CompareValidator>
        <br />
        <br />
        <asp:Button ID="sumButton" runat="server" onclick="Button1_Click" Text="Button" />
    
    </div>
    </form>
</body>


Default.aspx

protected void Button1_Click(object sender, EventArgs e)
{ Response.Redirect("Sum.aspx?Val1=" + txtVal1.Text + "&Val2=" + txtVal2.Text); }

Sum.aspx
int i, j, res;
protected void Page_Load(object sender, EventArgs e)
{
    i = Int32.Parse(Request.QueryString["Val1"]);
    j = Int32.Parse(Request.QueryString["Val2"]);
    res = i + j;
    Response.Write(res.ToString());
}


Related Blog

ASP.Net 2.0 Profile

Session Asp .Net : Storing DataSet

Saturday, June 14, 2008

Ajax ASP .Net VII : Accordion Control and CollapsiblePanelExtender

First let's see Ajax in action.

The page is displaying Shalvin's content by default. Only headers of Site and Contact Info are visible.








When you click on Site and Blog header, it will show its contents and other contents are invisible as shown in the figure below.













Having seen the functionality lets try to implement it.
Working with Accordion is a bit tough in comparison to the controls I have already explained because you won't get a visual interface for working with Accordion and you have to work this control in source view.

If you are not familiar working with Asp .Net is source view visit my blog Asp .Net Introduction : Notepad way



















Inside the Accordion tag place a Panes tag. Inside Panes you can have AccodionPane. AccordionPane inturn have Header and Content. I have added a b tag for Header. In real time you have to use CSS for better look and feel.


Accordion Databinding


Accordion control would most likely be used in conjunction with database data.



Here I am creating an SqlDataSource Control that point to Northwind database's Suppliers table.



I am setting the DataSourceId property of Accordion to the SqlDataSource id and creating HeaderTemplate and ContentTemplate as shown below.



If you are not comfortable working with templated controls visit my blog Asp .net DataList.


















Result

























Here I have made the header Bold and Underline. When you click on a header you can see the contents.










Adding CSS















CollapsiblePanelExtender

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server"
CollapseControlID="Header"
ExpandControlID= "Header"
TargetControlID="Content">
</asp:CollapsiblePanelExtender>
</div>

<asp:Panel ID="Header" runat="server" Height="16px" Width="293px">
<u>Shalvin P D </u></asp:Panel>

<asp:Panel ID="Content" runat="server">
.Net Consultant and Corporate trainer<br /> Blog :shalvinpd.blogspot.com
</asp:Panel>


Related Blogs




Ajax .Net I : Extension Controls in Visual Studio 2008


Ajax .Net II : Setting up Ajax Control Toolkit controls




Ajax .Net III : CalendarExtender Control


Ajax .Net IV : TextBoxWaterMarkExtender




Ajax .Net V : FilteredTextBoxExtender


Ajax .Net VI : ConfirmButtonExtender

Tuesday, June 10, 2008

.Net C# Multi Tier Application

The 3-Tier architecture has the following three tiers:

Data Tier
This tier consists of Database Servers. Here information is stored and retrieved. This tier keeps data neutral and independent from application servers or business logic. Giving data its own tier also improves scalability and performance.
Application Tier (Business Logic/Logic Tier)
The logic tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing.
Presentation Tier
This is the topmost level of the application. The presentation tier displays information related to such services as browsing merchandise, purchasing, and shopping cart contents. It communicates with other tiers by outputting results to the browser/client tier and all other tiers in the network.
Lets take up creating a very simple multi tier application.

First we will see the Data Tier. Here I am using Sql Server 2005 as data store.



















Now we will create the Application Tier or the Business Tier. For this I am creating a Class Library Project.

using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace ShalvinBusinessObject
{
public class BusinessObject
{
public DataTable GetCategories()
{
SqlConnection cnn;
SqlDataAdapter da;
DataSet ds = new DataSet();
cnn = new SqlConnection(@"Integrated Security=sspi;Initial Catalog=ShalvinPDBlog;Data Source=.\sqlexpress");
cnn.Open();
da = new SqlDataAdapter("spAllCategories", cnn);
da.Fill(ds, "Cat");
return ds.Tables["Cat"];
}
}

Goto Build, Build Solution for building the dll.

Creating the User Tier

Start a Windows Application Project.
Go to project, Add Reference, Select Browse and Navigate to the bin, release folder of the previously creating class library project. Select the dll.

Now you can access the dll from your project.



















using ShalvinBusinessObject;


BusinessObject bo;
private void Form1_Load(object sender, EventArgs e)
{
bo = new BusinessObject();
dataGridView1.DataSource = bo.GetCategories();
}

Here I am creating an Object of the Class in the previous dll and binding an dataGridView to the GetCategories method.

sqlcmd and Sql Server

sqlcmd is a command line tool for interacting with Sql Server.

Invoke the command prompt.














If your's is a low configuration machine sqlcmd is best tool since Sql Server Management studio is resource hungry.





sqlcmd -S .\sqlexpress
>create database ShalvinPDBlog
>go
>use ShalvinPDBlog
>create table Categories (
CategoryId int primary key identity(1,1), 
CategoryName varchar(20), Description varchar(60))
>go



Here -S points to the server name.



Related Blog
Transact Sql





For more information : http://msdn.microsoft.com/en-us/library/ms162773.aspx

SQL Server Authentication >sqlcmd -S .\sqlexpress -U sa -P s

Monday, June 9, 2008

Ajax .Net V : FilteredTextBoxExtender and MaskTextEditor

My initial intention of this series of blogs in to give an overview of 40 odd newly added controls. Later on I will editing these blogs and add extra information about each controls.

FilteredTextBoxExtender can be used as an aid to user preventing them from entering invalid data. For example you can allow only numeric, lower case, upper case or certain characters to be enetered into a textbox.


Add an Ajax Web Form, so that ScriptManager will be present on the form. Other wise just add a ScriptManager to the form.

Add an Asp .Net TextBox meant for entering Age. Add a FilteredTextBoxExtender set its TargetControlId property to the TextBox Id. Set the FilterType property to Numbers.




















Now it will allow only numeric input to the control.

As evident from the figure above you can set other filter types also.

Lets take up another another example similar to that demonstrated on http://www.asp.net/AJAX/AjaxControlToolkit/Samples/
where the input expected to be arithmetic operators.

Set the FilterType to Custom and ValidChars property to +-/*.

Don't rely entirely on FilteredTextBoxExtender because on disabling JavaScript on browser the user can bypass the filter. So it should be used more as an aid to the user.


MasktTextEditor

Land Phone
<asp:TextBox ID="txtLandPhone" runat="server"></asp:TextBox>
<asp:MaskedEditExtender ID="MaskedEditExtender1" runat="server"
Mask="9999-9999999" TargetControlID="txtLandPhone">
</asp:MaskedEditExtender>

Related Blog

Ajax .Net I : Extension Controls in Visual Studio 2008

Ajax .Net II : Setting up Ajax Control Toolkit controls

Ajax .Net III : CalendarExtender Control

Ajax .Net IV : TextBoxWaterMarkExtender

Ajax .Net VI : ConfirmButtonExtender

Ajax ASP .Net VII : Accordion Control

Sunday, June 8, 2008

C# Interface

An interface is a class with only signatures of methods properties and events without any implementation.
It is up to implementing class to add functionality . Your can't create an instance of interface.
Interface is an contract between an interface and implementing class that the implementing class should implements all the members of the interface.
It is possible to have multiple interface inheritance.

Start a new Windows Forms application or Wpf Application.

Add a new Interface by selecting Project, Add New Item and Interface from the Add NewItem Dialog.




















interface ISpecialization
{
string Specialization { get; set; }
}

Likewise create another Interface called IHobby.

interface IHobby
{
string Hobby { get; set; }
}


Now create a class which implements both ISpecailization and IHobby.

class Person : ISpecialization, IHobby
{
public string Hobby { get; set; }
public string Specialization { get; set; }
}

Now in Wpf Form you can instantiate Person class and use it.

Person Shalvin;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Shalvin = new Person();
Shalvin.Specialization = ".Net";
Shalvin.Hobby = "Blogging";
}

private void btnHobby_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(Shalvin.Hobby);
}

private void btnSpecialization_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(Shalvin.Specialization);
}




















Though we are using inheritance operator (:) behind the scene it is doing an implementation as is evident form the IL code below.
















If your are not conversant with Intermediate Language visi my blog : http://shalvinpd.blogspot.com/2008/02/intermediate-language.html

C# Express Edition : Creating Windows Forms User Control

Though there is no project template for User Control in C# Express Edition, it is possible to create User Controls with C# Express edition.

Start C# Express Edition. Start a new Class Library Project by selecting to File, New Project and Class Library from the New Project dialog.



















Go to Solution Explorer and delete the Class1.




























Go to Project menu and Select Add User Control give a good name.





















I am going to have a user control, which on clicking opens by blog in Internet explorer.

An User control is a border canvas. Place a Button Control give appropriate Text and Name to the Button.

In the click event of Button write the following code:





















You can't test an User Control in Express Edition at this point, thought such a feature is provided in Visual Studio.

You have to build the project first, make sure you save the project in an appropriate folder.















Now your control is ready for use.


For Consuming the User control start a new Windows Forms Application Project.
Lets create a new tab in tool box for our controls and give an appropriate name.


























Right click the newly created tab and select Choose Items.
























Choose Toolbox Items dialog will appear. Select Browse. In the Open Dialog navigate to the bin folder of the previously created project, go to debug directory (at the time of deployment the mode should be release) and select the dll.


















The control will appear in the toolbox and you can use the control by adding the control to the form just like ordinary Windows Forms Controls.

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());
}
}

Saturday, June 7, 2008

Ajax .Net IV : TextBoxWaterMarkExtender Control

For better look and feel you have to use CSS. But I will avoiding CSS to concentrate on the functionality of controls.


Ajax .Net TextBoxWaterMarkExtender Control is a simple control that extends Asp .Net Input controls.

Here is TextBoxWaterMarkExtender in action.















Here a text will appear inside the control, where you can specify extra information about the control. As you type inside the control the information text will vanish. In the figure above the information text of Name TextBox vanishes as I type my name inside the TextBox.

Start a new Asp .Net Project Place Asp .Net controls as shown in the figure. Add an Ajax .Net TextBoxWaterMarkExtender.
Go to properties window of TextBoxWaterMarkExtender and set TargetControlId to the control to the you want the information message to appear. In this case txtName












Now if the select the properties of TextBox you will see an extra property tab called Extender in this case where you can specify WatermarkText.












This will be the text that will be appearing on the control when the control is blank.

Related Blogs

Ajax .Net I : Extension Controls in Visual Studio 2008

Ajax .Net II : Setting up Ajax Control Toolkit controls

Ajax .Net III : CalendarExtender Control

Ajax .Net V : FilteredTextBoxExtender

Ajax .Net II : Setting up Ajax Control Toolkit controls

Ajax Control Toolkit is an shared source project from Microsoft.

Ajax .Net Extension Control comes packed with Visual Studio 2008, but not Ajax Control Toolkit Controls.

For accessing Ajax Control Toolkit you have to download Ajax Control Toolkit from www.asp.net/downloads.



















You can download Ajax Control Toolkit with or without source code.




















Unzip the Ajax Control Toolkit to a folder.

Add a new new tab to the Visual Studio 2008 toolbox give it a good name like say 'Ajax Contol Toolkit'.
Right click the newly added tab and choose Add item. Go to Browse tab, navigate to the folder where you unzipped the Ajax Control toolkit.
Navigate to Sample Web Site directory and navigate to bin folder. Select AjaxControlToolkit.dll.




















Click Open.
Now all the Ajax Control Toolkit controls will appear in the newly created toolbox.

























Related Blogs

Ajax .Net I : Extension Controls in Visual Studio 2008

Ajax .Net III : CalendarExtender Control

Ajax .Net VI : ConfirmButtonExtender




Happy Programming
shalvin.com

Friday, June 6, 2008

JavaScript in Asp .Net

For effectively working with Ajax .Net you are expected to have knowledge of JavaScript.

Let's see how to work with JavaScript in Xml.

alert
First lets review JavaScript and Html Controls.
Start a new Asp .net website .
Go to Html tag in Toolbox.

Drag and drop and drop an html input (Button). Set appropriate values for ID and Value. Double click on the Button.

You will be taken to the script section of the page.



















Type the alert javascript command as shown in the highlighted portion in the figure and run the application.

Click the Button and you will receive an alert as shown in the figure.



















prompt and Memory VariableJavaScript doesn't have data types.
We are going to prompt the user to type their name and later the user will be greeted with the user name they typed.














Run the application and Click on the Button. You will receive a prompt as shown in the figure below.





















Changing the Document Back Color
function btnRed_onclick() {
document.bgColor = "Red";
}

JavaScript and Asp .Net server ControlsHaving seen working with Html controls lets switch our focus to Server Controls.

Add an Asp .Net Button control. Go the the the source view of the Asp .Net page.
Now lets add the script section manually and a function called hello.
For wiring up the event handler use OnClientClick as highlighted in the figure.



















The drawback with using Asp.Net Button is it will ultimately result in a post back.

Working with dates
function Button1_onclick() {
var d = new Date();
alert(d);
}

Confirmfunction Button1_onclick() {
var r=confirm("Press a button");
if (r==true)
{
document.write("You pressed OK!");
}
else
{
document.write("You pressed Cancel!");
}
}

Functions

One speciality of JavaScript functions is that no error is generated when caller's parameter list does  not
match.  All parameters available  through built in arguments[].

<script language="javascript" type="text/javascript">
        function Button1_onclick() {
            var sum = Add(7, 4);
            alert(sum);
            var sum1 = Add(7, 8, 5);
            alert(sum1);
        }

        function Add()
        {
        var sum = 0;
        for (var i = 0; i < arguments.length; i++) {
            sum += arguments[i];
        }
        return sum;
        }
    </script>



Object in JavaScript
var Blog = { name: "Shalvin", blog: "ShalvinPD.blogspot.com" };

Blog.Specialization = ".Net";
Blog.Location = "Kochi";

alert(Blog.name + "'s blog is " + Blog.blog +
" specializing in " +
Blog.Specialization + " located at " + Blog.Location);


Related Blogs
http://javascript.crockford.com/survey.html