ASP.Net/Asp Control/Submit Button — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 26 мая 2010

ComboBox with Submit button (C#)

<%@ Page Language="c#" %>
<script runat="server">
    void Page_Load()
    {
       if (Page.IsPostBack)
         lblMessage.Text = "You have selected " + list1.SelectedItem.Value;
    }
</script>
<html>
<head>
    <title>Drop Down List Example</title>
</head>
<body>
    <asp:Label id="lblMessage" runat="server"></asp:Label>
    <br />
    <form runat="server">
        Which city interests you?<br />
        <asp:dropdownlist id="list1" runat="server">
            <asp:listitem>Madrid</asp:listitem>
            <asp:listitem>Oslo</asp:listitem>
            <asp:listitem>Lisbon</asp:listitem>
        </asp:dropdownlist>
        <input type="submit" value="Submit Query" />
    </form>
</body>
</html>



Handle form submit (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If Not IsPostBack Then
        Profession.Items.Add("Management")
        Profession.SelectedIndex = 2
        chkBreakfast.Checked= True
        radChicken.Checked = True
    End If
End Sub
Sub SubmitBtn1_Click(Source As Object, E as EventArgs)
    MyMessage.InnerHTML = "Hello " & UserName.Value _
        & ". Your password is " & Password.Value
End Sub
Sub SubmitBtn2_Click(Source As Object, E as ImageClickEventArgs)
    If radBeef.Checked = True Then
        MyMessage.InnerHTML = "So you want to eat beef?"
    Else
        MyMessage.InnerHTML = "So you want to eat chicken?"
    End If        
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Form Sample Page</TITLE>
</HEAD>
<BODY>
<form id="MyForm" Method="Post" runat="server">
  <Span id="MyMessage" runat=server>
  </Span>    
  <BR>    
  Name: 
  <BR>
  <Input id="UserName" runat="server" Type="text" MaxLength="50" Size="20" Value="Your Name">
  <BR>
  Password: 
  <BR>
  <Input id="Password" runat="server" Type="Password" MaxLength="50" Size="20"
  <BR>
  Address:<BR>
  <TextArea id="Address" runat="server" Cols="20" Rows="4">
Enter address here
</TextArea>
<BR>
Profession
<BR>
<Select
    id="Profession"
    runat="server"
    size=2
>
    <Option>Computers</Option>
    <Option>HR</Option>
</Select>
<BR>
Breakfast? 
<Input
    id="chkBreakfast"
    runat="server"
    type="checkbox"
>Lunch? 
<Input
    id="chkLunch"
    runat="server"
    type="checkbox"
    checked
>
Dinner? 
<Input
    id="chkDinner"
    runat="server"
    type="checkbox"
>
<BR>
Beef?
<Input
    id="radBeef"
    runat="server"
    type="radio"
    name="Meal"
>
Chicken?
<Input
    id="radChicken"
    runat="server"
    type="radio"
    name="Meal"
>
<BR><BR>
<input 
    runat="server"
    type="submit" 
    value="Submit Form" 
    OnServerClick="SubmitBtn1_Click" 
>
<input 
    runat="server"
    type="image"
    src="http://www.nfex.ru/style/logo.png" 
    OnServerClick="SubmitBtn2_Click" 
>
</Form>
</BODY>
</HTML>