1 / 11

Web Controls

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 ) {

chick
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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Web Controls

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

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

  4. Mixing Code With HTML <%@PageLanguage="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>

  5. Mixing Code With HTML :Server Side <%@PageLanguage="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>

  6. 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>

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

  8. 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/>"; } } }

  9. 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>

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

  11. 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 }

More Related