From the creation of a public opinion survey to talk about object-oriented programming ideas (V)

Source: Internet
Author: User

Well, now everything is ready, and we have nothing to worry about. Let's see how simple a public opinion survey is:

File: vote. aspx


<% @ Page language = "c #" Codebehind = "vote. cs" AutoEventWireup = "false" Inherits = "Football. vote" %>

<Html>
<Head>
<Title> 532.com.cn --- public opinion survey --- </title>
<Link rel = "stylesheet" href = "style/style.css" type = "text/css">

</Head>
<Body>

<Form method = "post" runat = "server">
<Table width = 400 height = 300 align = center>
<Tr>
<Td class = cn valign = top align = center> <B> survey subject:
<Asp: label id = "lblSurveyTitle" runat = Server class = cn> </asp: label>
</Td>
</Tr>
<Tr>
<Td alin = center>
<Asp: image id = "imgSurvey" runat = Server> </asp: image>
</Td>
</Tr>
<Tr>
<Td align = center>
<Input type = button onclick = "window. close ();" value = "close this window">
</Td>
</Tr>
</Table>
</Form>

</Body>
</Html>

File: vote. cs
Namespace Football
{
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;

/// <Summary>
/// Summary description for vote.
/// </Summary>
Public class vote: System. Web. UI. Page
{
Protected System. Web. UI. WebControls. Image imgSurvey;
Protected System. Web. UI. WebControls. Label lblSurveyTitle;

Private string m_strSurveyID;
Private int m_intVoteID;
Public vote ()
{
Page. Init + = new System. EventHandler (Page_Init );
}

Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
//
// Evals true first time browser hits the page
//
}
}

Protected void Page_Init (object sender, EventArgs e)
{
//
// CODEGEN: This call is required by the ASP + Windows Form Designer.
//
InitializeComponent ();
Init ();
}

/// <Summary>
/// Required method for Designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void InitializeComponent ()
{
This. Load + = new System. EventHandler (this. Page_Load );
}

Private void Init ()
{
M_strSurveyID = Request ["surveyid"]. ToString ();
FootballSurvey mySurvey = new FootballSurvey ();

Try
{
M_intVoteID = Request ["vote"]. ToInt32 ();
MySurvey. LoadFromDatabase (m_strSurveyID );
LblSurveyTitle. Text = mySurvey. Title;
If (m_intVoteID <mySurvey. Items. Count)
{
MySurvey. Vote (m_intVoteID );
}

MySurvey. CreateResultImage (Server. MapPath ("survey.jpg "),
MyClass. Util. MyChart. ChartType. Pie,
300,300, Color. White );
ImgSurvey. ImageUrl = "survey.jpg ";
}
Catch (Exception e)
{
# If DEBUG
Response. Write ("initialization page error:" + e. ToString ());
Return;
# Endif
Page. Navigate ("error. aspx ");
}

}
}
}

To view the results of this survey, go to http: // 210.12.102.95/football. Do you think this programming idea is good? What? Is it better to do it directly in the aspx file? Yes. If you do such a single investigation, it is really much easier to do, but do you know that as long as there is a compiled dll of this class, no matter how you change the page, change the data structure, can you do all the public opinion surveys you need within 15 minutes? This is the biggest difference between the two programming methods. I hope you can learn some programming ideas through this example.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.