Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web Controls Making a WebRequest using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO;

Similar presentations


Presentation on theme: "Web Controls Making a WebRequest using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO;"— Presentation transcript:

1

2 Web Controls

3 Making a WebRequest using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO;

4 Creating a WebRequest namespace WebRequestorApp { class Program { static void Main(string[] args) { WebRequest req = WebRequest.Create("http://www.microsoft.com"); WebResponse resp = req.GetResponse(); StreamReader reader = new StreamReader(resp.GetResponseStream(), Encoding.ASCII); Console.WriteLine(reader.ReadToEnd()); }

5 Mixing Code With HTML Hello World!!! <% // This block will execute in the Render_Control method Response.Write("Check out the family tree: "); Response.Write(this.GetType().ToString()); Response.Write(" which derives from: "); Response.Write(this.GetType().BaseType.ToString()); Response.Write(" which derives from: "); Response.Write(this.GetType().BaseType.BaseType.ToString()); Response.Write(" which derives from: "); Response.Write( this.GetType().BaseType.BaseType.BaseType.ToString()); Response.Write(" which derives from: "); Response.Write( this.GetType().BaseType.BaseType.BaseType.BaseType.ToString ()); %>

6 Mixing Code With HTML :Server Side void ShowLineage() { Response.Write("Check out the family tree: "); Response.Write(this.GetType().ToString()); Response.Write(" which derives from: "); Response.Write(this.GetType().BaseType.ToString()); Response.Write(" which derives from: "); Response.Write(this.GetType().BaseType.BaseType.ToString()); Response.Write(" which derives from: "); Response.Write( this.GetType().BaseType.BaseType.BaseType.ToString()); Response.Write(" which derives from: "); Response.Write( this.GetType().BaseType.BaseType.BaseType.BaseType.ToString()); } Hello World!!! <% ShowLineage(); %>

7 Dropdown List <div style= "font-family: 'Times New Roman', Times, serif; font-size: 14pt; font-weight: bold"> Page in Visual Studio Item 1 Item 2 Item 3 Item 4 Item 5 Item 6

8 DropDownList Code protected void Button1_Click(object sender, EventArgs e) { Response.Write("Hello. Here's what you typed into the text box: "); Response.Write(this.TextBox1.Text); Response.Write(" "); Response.Write("And the selected item is: "); Response.Write(this.DropDownList1.SelectedItem.Text); }

9 CheckBoxList protected void Button1_Click(object sender,System.EventArgs e) { Label1.Text = "You Selected: "; foreach (ListItem li in CheckBoxList1.Items){ if (li.Selected == true){ Label1.Text += li.Text + " "; }

10 RadioButtonList My level of education is:<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"> Primary school Middle school High School Vocational college Bachelors degree Masters degree PhD or other doctorate

11 The Code protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = "Your level of education is " + RadioButtonList1.Text; }

12 The ListBox Assuming that you created a ListBox lstEmployees: Protected void btnAdd_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 = new ListItem (); //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 }


Download ppt "Web Controls Making a WebRequest using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO;"

Similar presentations


Ads by Google