Web controls
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Web Controls PowerPoint PPT Presentation


  • 64 Views
  • Uploaded on
  • Presentation posted in: General

Web Controls. Making a WebRequest. using System; using System.Collections.Generic ; using System.Linq ; using System.Text ; using System.Net ; using System.IO;. Creating a WebRequest. namespace WebRequestorApp { class Program { static void Main( string [] args ) {

Download Presentation

Web Controls

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Web controls

Web Controls


Making a webrequest

Making a WebRequest

using System;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Net;

using System.IO;


Creating a webrequest

Creating a WebRequest

namespaceWebRequestorApp

{

classProgram

{

staticvoid Main(string[] args)

{

WebRequestreq = WebRequest.Create("http://www.microsoft.com");

WebResponseresp = req.GetResponse();

StreamReader reader = newStreamReader(resp.GetResponseStream(), Encoding.ASCII);

Console.WriteLine(reader.ReadToEnd());

}

}

}


Mixing code with html

Mixing Code With HTML

<[email protected]="C#"Debug="true" %>

<html>

<body>

<h1>Hello World!!!</h1>

<%

// This block will execute in the Render_Control method

Response.Write("Check out the family tree: <br/> <br/>");

Response.Write(this.GetType().ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(this.GetType().BaseType.ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(this.GetType().BaseType.BaseType.ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(

this.GetType().BaseType.BaseType.BaseType.ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(

this.GetType().BaseType.BaseType.BaseType.BaseType.ToString());

%>

</body>

</html>


Mixing code with html server side

Mixing Code With HTML :Server Side

<[email protected]="C#"Debug="true" %>

<scriptrunat="server">

voidShowLineage()

{

Response.Write("Check out the family tree: <br/> <br/>");

Response.Write(this.GetType().ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(this.GetType().BaseType.ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(this.GetType().BaseType.BaseType.ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(

this.GetType().BaseType.BaseType.BaseType.ToString());

Response.Write(" which derives from: <br/> ");

Response.Write(

this.GetType().BaseType.BaseType.BaseType.BaseType.ToString());

}

</script>

<html>

<body> <h1>Hello World!!!</h1>

<%

ShowLineage();

%>

</body>

</html>


Dropdown list

Dropdown List

<formid="form2"runat="server">

<divstyle=

"font-family: 'Times New Roman', Times, serif; font-size: 14pt; font-weight: bold">

Page in Visual Studio<br/>

<asp:LabelID="Label1"runat="server"Text="Type in me:"></asp:Label>

<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>

<br/>

<asp:DropDownListID="DropDownList1"runat="server">

<asp:ListItem>Item 1</asp:ListItem>

<asp:ListItem>Item 2</asp:ListItem>

<asp:ListItem>Item 3</asp:ListItem>

<asp:ListItem>Item 4</asp:ListItem>

<asp:ListItem>Item 5</asp:ListItem>

<asp:ListItem>Item 6</asp:ListItem>

</asp:DropDownList>

<br/>

<asp:ButtonID="Button1"runat="server"Text="Click Me"/>

</div>

</form>


Dropdownlist code

DropDownList Code

protectedvoid Button1_Click(object sender, EventArgs e)

{

Response.Write("Hello. Here's what you typed into the text

box: <br/>");

Response.Write(this.TextBox1.Text);

Response.Write("<br/>");

Response.Write("And the selected item is: <br/>");

Response.Write(this.DropDownList1.SelectedItem.Text);

}


Checkboxlist

CheckBoxList

protectedvoidButton1_Click(objectsender,System.EventArgs e)

{

Label1.Text = "You Selected:<br/>";

foreach (ListItem li in CheckBoxList1.Items){

if (li.Selected == true){

Label1.Text += li.Text + "<br/>";

}

}

}


Radiobuttonlist

RadioButtonList

<formid="form2"runat="server">

<divstyle="text-align: left">

<br/>

My level of education is:<asp:RadioButtonListID="RadioButtonList1"

runat="server"AutoPostBack="True"

onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">

<asp:ListItem>Primary school</asp:ListItem>

<asp:ListItem>Middle school</asp:ListItem>

<asp:ListItem>High School</asp:ListItem>

<asp:ListItem>Vocational college</asp:ListItem>

<asp:ListItem>Bachelors degree</asp:ListItem>

<asp:ListItem>Masters degree</asp:ListItem>

<asp:ListItem>PhD or other doctorate</asp:ListItem>

</asp:RadioButtonList>

<br/>

<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>

</div>

</form>


The code

The Code

protectedvoid RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)

{

Label1.Text = "Your level of education is " +

RadioButtonList1.Text;

}


The listbox

The ListBox

Assuming that you created a ListBoxlstEmployees:

Protected voidbtnAdd_Click(object sender, EventArgs e)

{ if (lstEmployees.SelectedIndex > -1)

{ string_value = lstEmployees.SelectedItem.Value;//Gets the value of items in list.

string _text = lstEmployees.SelectedItem.Text;//Gets the Text of items in the list.

ListItem item = newListItem (); //create a list item

item.Text = _text; //Assign the values to list item

item.Value = _value;

lstSelectedEmployees.Items.Add(item); //Add the list item to the selected list of employees

lstEmployees.Items.Remove(item); //Remove the details from employee list

}


  • Login