Mega Code Archive

 
Categories / ASP.Net / Language Basics
 

Define function to change HR length (C#)

<%@ Page Language="C#" Debug="true" %> <script runat="server">     void Page_Load()     {         if (IsPostBack)         {                  lblMessage.Text = "First Line";             InsertLinebreak(Convert.ToInt32(NumberOptions.SelectedItem.Value),                             Convert.ToInt32(WidthOptions.SelectedItem.Value));             lblMessage.Text += "Second Line";             InsertLinebreak(Convert.ToInt32(NumberOptions.SelectedItem.Value),                             Convert.ToInt32(WidthOptions.SelectedItem.Value));         }     }          void InsertLinebreak(int NumLines, int Width)     {         for (int i=1; i<=NumLines; i++)         {            lblMessage.Text += "<br><hr width='" + Width.ToString() +                               "' align='left'>";         }     } </script> <html> <head>     <title>Using Functions with Parameters</title> </head> <body>     Choose the number and width of the linebreaks and then press submit      <form runat="server">         <asp:RadioButtonList id="WidthOptions" runat="server">             <asp:ListItem value="100">100 pixels wide</asp:ListItem>             <asp:ListItem value="300">300 pixels wide</asp:ListItem>             <asp:ListItem value="600">600 pixels wide</asp:ListItem>         </asp:RadioButtonList>         <asp:DropDownList id="NumberOptions" runat="server">             <asp:ListItem value="1">1 Line</asp:ListItem>             <asp:ListItem value="2">2 Lines</asp:ListItem>             <asp:ListItem value="3">3 Lines</asp:ListItem>         </asp:DropDownList>         <asp:Button id="Button1" runat="server" text="Submit"></asp:Button>         <br />         <br />         <asp:Label id="lblMessage" runat="server"></asp:Label>     </form> </body> </html>