110 likes | 268 Views
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 ) {
E N D
Making a WebRequest using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Text; usingSystem.Net; using System.IO;
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 <%@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>
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>
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 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 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 <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 protectedvoid RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = "Your level of education is " + RadioButtonList1.Text; }
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 }