ckeditor in asp.net - asp.net

I have to use a ckeditor in my application but I dont know how to write the
# Register Assembly="" Namespace="" TagPrefix="" %>
From where I could get the assembly?

In web.config section you can write:
<add tagPrefix="FredCK" namespace="FredCK.CKEditor" assembly="FredCK.CKEditor, Culture=neutral, PublicKeyToken=9ef91de3e191403a" />

Actually, best is not to use the ASP.NET CKEditor control but use CKEditor directly. The control is outdated (version 3.6 instead of 4.1) and not necessary. Basically, use a multiline textbox and make it of the class CKEditor. Don't forget to add the ckEditor.js to the head section:
web.config
<configuration>
<system.web>
<httpRuntime requestValidationMode="2.0"/>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
Test.aspx
<!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>ckeditor test page</title>
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:TextBox class="ckeditor" ID="CkeditorTextBox" runat="server" TextMode="MultiLine" Columns="80" Rows="10">
Hi
</asp:TextBox>
</p>
<p>
<asp:Button ID="SubmitButton" runat="server" onclick="SubmitButton_Click" Text="Submit" />
</p>
</form>
</body>
</html>
Test.aspx.cs
using System;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SubmitButton_Click(object sender, EventArgs e) {
string CkEditorText = CkeditorTextBox.Text;
//add some processing here
}
}

There is a nice asp.net wrapper control for the ckeditor: http://cksource.com/forums/viewtopic.php?f=11&t=15882

The answer will be
scrpt type = "text/javascript" src = "ckeditor/ckeditor.js"....close script
//ckeditor is the folder that you have created in your application.
script type="text/javascript"
window.onload = function()
{
debugger
vartxtDemo = document.getElementByID('<%txtDemo.ClientID%');
CKEDITOR.replace(txtDemo);
}...//close the script
but before that make a ckeditor folder in your application and paste the contents that you have downloaded,

Related

ASP.NET Cache contains solution path

Why does my Cache object contain a single entry containing the following? Shouldn't it be empty? And if not, obviously there is this ugly default value in the Cache object...how do I remove it? I haven't added anything to the Cache object, yet it contains this item below.
__System.Web.WebPages.Deployment__C:\Users\Danny\Documents\Visual Studio 2010\Projects\LearningAOP\WebAppCachingII\WebAppCachingII\***C:\Users\Danny\Documents\Visual Studio 2010\Projects\LearningAOP\WebAppCachingII\WebAppCachingII\
Here is my ASP.NET code-behind, the markup has a single bulleted list control;
using System;
using System.Collections;
using System.Linq;
using System.Web.UI.WebControls;
namespace WebAppCachingII
{
public partial class CachingDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
foreach (DictionaryEntry cacheditem in Cache)
{
var concatstring = cacheditem.Key + "***" + cacheditem.Value;
listOfCacheItems.Items.Add(new ListItem(concatstring));
}
}
}
}
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CachingDemo.aspx.cs" Inherits="WebAppCachingII.CachingDemo" %>
<!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:BulletedList ID="listOfCacheItems" runat="server" /> </div>
</form>
</body>
</html>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<caching>
<outputCache enableOutputCache="false" />
</caching>
</system.web>
</configuration>

Validation of viewstate MAC failed when ran from Visual Studio 2010

I am receiving the below error from a very simple web application ran directly from Visual Studio 2010 with framework 4.0.
Server Error in '/' Application.
Validation of viewstate MAC failed. If this application is hosted by a
Web Farm or cluster, ensure that configuration specifies
the same validationKey and validation algorithm. AutoGenerate cannot
be used in a cluster.
Here is my application files
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<!--<machineKey validationKey="08367F8C07194695F9714CB86778E9031DFAC34ECAE8DE9944CE7E765EB8B6F56D0DDE9C95639F01DF94597D4FFFF42BFCDB0A71544755C70683D6B95D3D3E5B" decryptionKey="DF5FA3F9EA83B31D9BF1381539CD90E3D4AEA74FEE490E5C1B0A160A4CCA7DA2" validation="SHA1" decryption="AES" />-->
<pages enableViewState="false"></pages>
</system.web>
</configuration>
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test.Default" %>
<!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" method="post" action="info.aspx">
<div>
<input type="hidden" name="data" value="this is post data" />
<input type="submit" name="Submit" value="Submit" />
</div>
</form>
</body>
</html>
info.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test
{
public partial class info : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string x = Request.Form["data"];
}
}
}
I tried all possible solutions given over internet but in vain.
Added machine key {not worked}
Added enableViewState="false" {not worked}
I am desperately trying to understand why this behaviour?
Have you tried using ASP.net proper hidden as opposed to input?
<asp:HiddenField ID="data" value="this is post data" runat="server" />

Simple website doesn't work on server

i have a very simple websote just for experimentation.
On my local machine it works but when i put it on the server i get "Server Error in '/' Application.Runtime Error "
defaul.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="default.aspx.cs" Inherits="_default"%>
<!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>
</div>
</form>
</body>
</html>
default.aspx.cs:
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)
{
}
}
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<directoryBrowse enabled="false" />
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
But when i change the aspx file it works (i've removed:CodeFile="default.aspx.cs" and Inherits="_default")
<%# Page Language="C#" AutoEventWireup="true"%>
<!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>
</div>
</form>
</body>
</html>
Turns out that if i remove the System.Linq from my aspx.cs file the site does work.
Is the Framework version correct for the application pool on the server?
You've stated that it works if you remove System.Linq which could point at the Framework version being incorrect on the application pool
The other thing to check is to make sure you're not running sites built on different version of the .Net framework in the same application pool as they will kill each other and you'll get the dreaded "Server Error in '/' Application. Runtime Error"
Please check two dlls must be in your Bin folder on the server
1) System.Web.Extensions.dll
2) System.Web.Extensions.Design.dll

How to add namespace in aspx file?

i have added C# code in aspx file, but it is showing error
The type or namespace name 'Mail' does not exist in the class or
namespace 'System.Net' (are you missing an assembly reference?)
How i can add nampespace to aspx file i have tried <%# import namespace="Westwind.Tools"%> but it does not work?
<%# Import Namespace="System.Net.Mail" %>
I'm assuming that it's in a website and that the page doesn't have code behind?
<%# Page Language="C#" %>
<%# Import Namespace="System.Net.Mail"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
System.Net.Mail.SmtpClient client = new SmtpClient();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
</body>
</html>
This seems to work for me.
If it's not in a website and/or it has code behind why do you need to reference the namespace in the aspx file?
Hope this helps
To add the namespace globally instead of page-by-page, just put the namespace in your web.config.
<configuration>
<system.web>
<pages>
<namespaces>
<add namespace="Your.Namespace"/>
</namespaces>
</pages>
</system.web>
</configuration>
You might have to restart Visual Studio for the IntelliSense to kick in.
You can also create a mini web.config in a directory to only import the namespace into ASPX files within that directory and sub-directories instead of applying it globally.
You can import and create an optional alias for the namespace:
<%# Import Namespace="SP=Microsoft.SharePoint.Client" %>
and then use the alias like:
<%= var spContext = new SP.ClientContext("someSharePointUrl"); %>

Listview and SQLDataSource render nothing

I've never used either of these 2 controls before and I'm stuck with no visible rendering of the page (compiles and runs but produces nothing); I have no code behind file with this simple asp.net page and I am using Visual Studio 2008:
<%# Page Language="C#" AutoEventWireup="true"
CodeBehind="Index.aspx.cs" Inherits="zList.Index" %>
<!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:ListView ID="CategoryList" runat="server"
DataSourceID="Categories">
<LayoutTemplate>
<ol>
<asp:PlaceHolder runat="server" ID="itemPlaceholder">
</asp:PlaceHolder>
</ol>
</LayoutTemplate>
<ItemTemplate>
<li><%# Eval("AttrDesc")%></li>
</ItemTemplate>
</asp:ListView>
</div>
</form>
</body>
</html>
<asp:sqldatasource runat="server" id="Categories"
ConnectionString="<%$ ConnectionStrings:ZIPeeeConnectionString2 %>"
SelectCommand="SELECT AttrID,AttrDesc FROM dbo.tblAttributes1">
</asp:sqldatasource>
Here is the connection string section from web.config (I have tried both connection strings separately and they both result in nothing rendered):
<connectionStrings>
<add name="ZIPeeeConnectionString" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ZIPeeeConnectionString2" connectionString="Data Source=MOJITO;Initial Catalog=ZIPeee;User ID=sa;Password=" providerName="System.Data.SqlClient"/>
</connectionStrings>
I am getting no runtime errors and no errors during the build. The simple query works fine from SQL Query Analyzer (i.e. SQL Server 2000). Any ideas?
EDIT-UPDATE:
Here is what I have in my .ASPX.CS code behind file and I cannot get the debugger to stop on the breakpoint on the .DataBind method:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace zList
{
public partial class Index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CategoryList.DataBind(); // breakpoint set here but debugger won't stop here
}
}
}
By the way, I fired up SQL Profiler and it appears the SQL select is not even being fired against
the server. As I said, the page is empty - just this junk when I scrape it via View Page Source:
<!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><title></title></head>
<body>
<form name="form1" method="post" action="Index.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjAyMTkwMzQ3OQ9kFgQCAw9kFgICAQ8UKwACDxYEHgtfIURhdGFCb3VuZGceC18hSXRlbUNvdW50Av////8PZGRkAgUPD2QPEBYDZgIBAgIWAxYCHg5QYXJhbWV0ZXJWYWx1ZWQWAh8CZBYCHwJkFgMCAwIDAgNkZBgBBQxDYXRlZ29yeUxpc3QPZ2TCuhjvuwDRjaGJssTwiDXpAv/fdw==" />
</div>
<div>
</div>
</form>
</body>
</html>
I think the only thing wrong with this code is the placement of the sqldatasource. Can you place it inside the tag.
If that doesnt work, can you change your listview definition to
<asp:ListView ID="CategoryList" runat="server">
and then change your page load code to
CategoryList.DataSource = Categories;
CategoryList.DataBind();
You should be able to hit the debugger
As a last option, can you also check whether the connectionstrings is placed within the Configuration tag in web.config.

Resources