C# [ASP.net] Ajax Control Toolkit HTML Editor

henne10

Lt. Junior Grade Pro
Registriert
Dez. 2007
Beiträge
439
Hallo CB'ler,

ich versuche grade den Editor in einem Projekt von/für VirtualStudio 2008 einzubinden.
Wenn ich ein Projekt über File --> New Projekt --> Visual C# --> Web --> ASP.NET Web Application erstelle funktioniert das ganz nicht.
Sobald ich aber das ganze noch mal als New Web Site mache funktioniert's und ich kann auf die Controls in der cs File zugreifen.
In dem Projekt sagt er mir immer nur
The name 'XYZ' does not exist in the current context File
oder
The type or namespace name 'MyEditor' could not be found (are you missing a using directive or an assembly reference?)
Das Ajax Toolkit ist aber als References angegeben.

Wisst ihr eine Lösung wie man den Editor in einem Projekt zum laufen bringt (als Web Site geht's nicht es muss ein Projekt sein)? Ich bin mit meinem Latein am Ende.
 
Hi,

Wie genau bindest Du es ein. Sagst Du "Add existing Item"? Ist der namespace 'MyEditor' von Dir?

lg, Rainer
 
Hi,

Ja der namespace ist 'MyEditor' und liegt im App_Code Ordner. Eingebunden habe ich es über New Item --> Code File.
 
Möchtest Du den Source Code des Ediotrs ändern oder einfach nur das Control verwenden? Bei zweiterem brauchst Du nur folgendes zu machen:

Code:
<%@ Register
    Assembly="AjaxControlToolkit"
    Namespace="AjaxControlToolkit.HTMLEditor"
    TagPrefix="HTMLEditor" %>
...
<HTMLEditor:Editor runat="server" 
        Height="300px" 
        Width="100%"
        AutoFocus="true"
/>
 
ich möchte beides...
hier mal einwenig Code vllt. verdeutlicht das ja mein Vorhaben.


MyEditor.cs:

Code:
using System.Collections;
using System.Collections.ObjectModel;
using AjaxControlToolkit.HTMLEditor;
using AjaxControlToolkit.HTMLEditor.ToolbarButton;

namespace MyEditor
{
    public class CustomEditor : Editor
    {
        protected override void FillTopToolbar()
        {
            Collection<SelectOption> options;
            SelectOption option;

            TopToolbar.Buttons.Add(new Bold());
            TopToolbar.Buttons.Add(new Italic());
            TopToolbar.Buttons.Add(new Underline());
            TopToolbar.Buttons.Add(new HorizontalSeparator());

            TopToolbar.Buttons.Add(new RemoveAlignment());
            TopToolbar.Buttons.Add(new JustifyCenter());
            TopToolbar.Buttons.Add(new HorizontalSeparator());

            TopToolbar.Buttons.Add(new OrderedList());
            TopToolbar.Buttons.Add(new BulletedList());
            TopToolbar.Buttons.Add(new DecreaseIndent());
            TopToolbar.Buttons.Add(new IncreaseIndent());
            TopToolbar.Buttons.Add(new HorizontalSeparator());

  
            AjaxControlToolkit.HTMLEditor.ToolbarButton.FontSize fontSize = new FontSize();
            TopToolbar.Buttons.Add(fontSize);

            options = fontSize.Options;
            option = new SelectOption();
            option.Value = "12pt";
            option.Text = "3 (12 pt)";
            options.Add(option);
            option = new SelectOption();
            option.Value = "14pt";
            option.Text = "4 (14 pt)";
            options.Add(option);
        }

        protected override void FillBottomToolbar()
        {
            //BottomToolbar.Buttons.Add(new DesignMode());
            //BottomToolbar.Buttons.Add(new PreviewMode());
        }
    }

    public class ShowEditor : CustomEditor
    {
        protected override void FillTopToolbar()
        {
        }
        protected override void FillBottomToolbar()
        {
        }
    }
}

Default.aspx

Code:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register namespace="MyEditor" tagPrefix="act" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <asp:ScriptManager ID="ScriptManager1" runat="server"/>
      <act:CustomEditor ID="Editor1"  Width="450px" Height="200px" runat="server" />
      <asp:Button ID="Submit" Text="Absenden" runat="server" OnClick="ButtonSubmit_Click" />
      <br />
      <asp:Literal ID="LbContent" runat="server" />
      <br />
      <act:ShowEditor ID="Anzeige" Width="450px" Height="200px" ActiveMode="Preview" runat="server" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs:

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ButtonSubmit_Click(object sender, EventArgs e)
    {
        LbContent.Text = Editor1.Content;
        String StrEditor1 = Editor1.Content.ToString();        
    }
}


so geht's wenn es als Web Site erstellt wurde, wenn man das nun aber als Projekt erstellt sagt er:
The name 'Editor1' does not exist in the current context
Ergänzung ()

weiß keiner einen Ansatz wie man das Problem lösen könnte?
Ergänzung ()

Problem scheinbar gelöst...

protected global::AjaxControlToolkit.HTMLEditor.Editor Editor1;

einfach der Default.aspx.designer.cs File hinzugefügt und er findet's auch in der Default.aspx.cs
 
Zurück
Oben