Wednesday, 29 February 2012

Use of ajax HtmlEditorExtender

Design a table in ur database:
Design the user inter face like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
.accordionContent
{
background-color: #D3DEEF;
border-color: -moz-use-text-color #2F4F4F #2F4F4F;
border-right: 1px dashed #2F4F4F;
border-style: none dashed dashed;
border-width: medium 1px 1px;
padding: 10px 5px 5px;
width:20%;
}
.accordionHeaderSelected
 {
background-color: #5078B3;
border: 1px solid #2F4F4F;
color: white;
cursor: pointer;
font-family: Arial,Sans-Serif;
font-size: 12px;
font-weight: bold;
margin-top: 5px;
padding: 5px;
width:20%;
}
.accordionHeader
{
background-color: #2E4D7B;
border: 1px solid #2F4F4F;
color: white;
cursor: pointer;
font-family: Arial,Sans-Serif;
font-size: 12px;
font-weight: bold;
margin-top: 5px;
padding: 5px;
width:20%;
}
.href
{
color:White;
font-weight:bold;
text-decoration:none;
}
</style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <div>
    <asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
    <table align="center">
    <tr><td>  <asp:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="tb">
        </asp:HtmlEditorExtender>
        <asp:TextBox ID="tb" runat="server" TextMode="MultiLine" Height="300" Width="600"></asp:TextBox></td></tr>
        <tr><td align="center"><asp:Button ID="btn" runat="server" Text="Save" Width="80"
                onclick="btn_Click" />&nbsp;<asp:Button ID="Button1" runat="server" Text="Reset" Width="80" /></td></tr>
        <tr><td>
        <asp:Repeater ID="rpt" runat="server">
        <ItemTemplate>
        <asp:Literal ID="ltr" runat="server" Text='<%#Eval("name")%>'></asp:Literal>
        </ItemTemplate>
        <SeparatorTemplate>
        <hr />
        </SeparatorTemplate>
        </asp:Repeater>
        </td></tr>
    </table>
    </ContentTemplate>
    </asp:UpdatePanel>
     
    </div>
    </form>
</body>
</html>


 C# CODE :



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
#region
    DataClassesDataContext o =new DataClassesDataContext(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString());
#endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            view();
    }
    protected void btn_Click(object sender, EventArgs e)
    {
        EMP p = new EMP();
        p.NAME = tb.Text;
        o.EMPs.InsertOnSubmit(p);
        o.SubmitChanges();
        view();
    }
    void view()
    {
        var m = from x in o.EMPs select x;
        rpt.DataSource = m;
        rpt.DataBind();
    }
}


No comments:

Post a Comment