The first ASP. NET Component I wrote"

Source: Internet
Author: User

Demo. aspx code:
<% @ Inherits = "featuredproduct" %>
<Script language = "C #" runat = "server">
Void btnsetbgcolor_click (Object S, eventargs E)
{
Setbackcalor (txtbgcolor. Text );
}
Void btnsubmit_click (Object S, eventargs E)
{
Add (txtusername. Text, txtcontent. Text );
}
</SCRIPT>
& Lt; table width = "200" cellpadding = "10"
Cellspacing = "0" bgcolor = "<% = backcolor %>">
<Tr>
<TD>
<H3> Blenders on sale! </H3>
See our selection of blenders in
Home Appliance deparment.
</TD>
</Tr>
</Table>
<Form runat = "server">
Input color:
<Asp: textbox id = "txtbgcolor" runat = "server"/>
<Asp: button id = "btnsetbgcolor" onclick = "btnsetbgcolor_click" text = "set color" runat = "server"/>
<Br>
Username:
<Asp: textbox id = "txtusername" runat = "server"/>
<Br>
Content:
<Asp: textbox id = "txtcontent" runat = "server"/>
<Br>
<Asp: button id = "btnsubmit" onclick = "btnsubmit_click" text = "Submit message" runat = "server"/>
</Form>

Featuredproduct. CS code:
Using system;
Using system. Data;
Using system. Data. oledb;
Using system. Web. UI;
Using system. Web. UI. webcontrols;

Public class featuredproduct: system. Web. UI. Page
{
Public String backcolor = "lightgreen ";
Public void setbackcalor (string Str)
{
Backcolor = STR;
}
Public void add (string username, string content)
{
Oledbconnection conconnection = new oledbconnection ("provider = Microsoft. Jet. oledb.4.0; Data Source =" + server. mappath ("./db1.mdb "));
Oledbcommand into command = new oledbcommand ("insert into guestbook (username, content) values ('" + username + "', '" + content + "')", conconnection );
Conconnection. open ();
Using command. executenonquery ();
Conconnection. Close ();
}
}

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.