Home   Cover Cover Cover Cover



<%@ Page Language="C#" Inherits="Registration" Src="Registration.aspx.cs" %>
    <title>Registration for the .NET seminar</title>
    <h2>Use this page to register for the .NET seminar</h2>
    <form method="post" Runat="server">
            <asp:TextBox ID="name" Width="300" Runat="server"/>
          <td>First Name</td>
            <asp:TextBox ID="firstName" Width="300" Runat="server"/>
            <asp:TextBox ID="email" Width="300" Runat="server"/>
          <td> </td>
            <asp:CheckBox ID="workshop" Text="with workshop" Runat="server"/>
          <td> </td>
            <asp:RadioButton ID="programmer" Text="programmer" GroupName="job" Checked="true" Runat="server"/><br>
            <asp:RadioButton ID="webDesigner" Text="web designer" GroupName="job" Runat="server"/><br>
            <asp:RadioButton ID="manager" Text="manager" GroupName="job" Runat="server"/>
      <asp:Button ID="submit" Text="Register" OnClick="Register" Runat="server"/>
      <asp:Label ID="message" ForeColor="Red" Text="" Runat="server"/>


using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;

public class Registration : Page {
  protected TextBox name;
  protected TextBox firstName;
  protected TextBox email;
  protected CheckBox workshop;
  protected RadioButton programmer;
  protected RadioButton webDesigner;
  protected RadioButton manager;
  protected Button submit;
  protected Label message;
  public void Register(object sender, EventArgs e) {
    if (name.Text == "")
      message.Text = "Please fill in all text fields";
    else {
      try {
        FileStream s = new FileStream(Server.MapPath("registrations.txt"), FileMode.Append, FileAccess.Write);
        StreamWriter w = new StreamWriter(s, Encoding.UTF8);
        w.Write(name.Text + " " + firstName.Text + " " + email.Text);
        if (workshop.Checked) w.Write(" +workshop");
        if (programmer.Checked) w.Write(" programmer");
        else if (webDesigner.Checked) w.Write(" designer");
        else if (manager.Checked) w.Write(" manager");
        message.Text = "Thank you for registering";
      } catch (IOException) {
        message.Text = "An error occurred while processing your request";


Klicken Sie hier.