Telerik RadEditor HTTP POST VALUE 未更新(ASP.NET Web 表单)

发布于 2024-12-07 05:04:53 字数 1642 浏览 1 评论 0原文

我目前正在 ASP.NET 中编写 ContentManager。我有一个预览按钮,它使用 jQuery 将表单数据发布到新窗口,并显示页面的外观,而无需将其保存到数据库并影响实时站点。虽然让 ASP.NET 直接发布到我试图预览的页面有点麻烦,但我最终使用一系列 jQuery 代码解决了这一切。它工作得很好,我使用 Request.Form 将所有发布值加载到页面中并将它们显示在页面上。不幸的是,由于某种原因,我使用的 Telerik RadEditor 向我发布了它们在 C# Page_Load 事件上分配的值,并且没有反映我所做的文本更改。如果有人能帮助我那就太好了。

function showPreview()
{
    url = "<%= (SiteManager.GetSite()).Url  + this.Filename %>?preview=true"; 
    var specs = "width=1010,height=700,location=0,resizeable=1,status=1,scrollbars=1"; 
    window.open(url, 'PagePreview', specs).moveTo(25, 25);
    $("#__VIEWSTATE").remove();
    $("#__EVENTTARGET").remove();
    $("#__EVENTARGUMENT").remove();
    $("#aspnetForm").removeAttr("action");
    $("#aspnetForm").attr("target","PagePreview");
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit(); 
}

这是我从 tererik RADEDITOR 收到的所有帖子数据 ::

[ctl00_MainContentPlaceHolder_SideContentRadEditor_dialogOpener_Window_ClientState] => [ctl00_MainContentPlaceHolder_SideContentRadEditor_dialogOpener_ClientState] => [ctl00$MainContentPlaceHolder$SideContentRadEditor] => [ctl00_MainContentPlaceHolder_SideContentRadEditor_ClientState] => [ctl00_MainContentPlaceHolder_ContentRadEditor_dialogOpener_Window_ClientState] => [ctl00_MainContentPlaceHolder_ContentRadEditor_dialogOpener_ClientState] => [ctl00$MainContentPlaceHolder$ContentRadEditor] => %3cp%3eTestPageContent%3c/p%3e 

这是文本编辑器的 html 值(如上所示)%3cp%3eTestPageContent%3c/p%3e 这是在 Page_Load 事件期间加载的 RadEditor 中的值。

我将值更改为“测试”。但它不是通过 POST 请求发送的,而是发送了页面加载中加载的内容。

I am currently writing a ContentManager in ASP.NET. I have a preview button which uses jQuery to post the form data to new window and shows how a page would look without saving it to the database and effecting the live site. Although its been somewhat of a hassle to get ASP.NET to post directly to the page I am trying to preview, I've finally worked it all out using a series of jQuery code. It worked beautifully, I loaded all the post values into the page using Request.Form and displayed them on the page. Unfortunately for some reason the Telerik RadEditor's I was using were posting me the values they had been assigned on the C# Page_Load event and did not reflect the text changes I made. If anyone could help me out that would be great.

function showPreview()
{
    url = "<%= (SiteManager.GetSite()).Url  + this.Filename %>?preview=true"; 
    var specs = "width=1010,height=700,location=0,resizeable=1,status=1,scrollbars=1"; 
    window.open(url, 'PagePreview', specs).moveTo(25, 25);
    $("#__VIEWSTATE").remove();
    $("#__EVENTTARGET").remove();
    $("#__EVENTARGUMENT").remove();
    $("#aspnetForm").removeAttr("action");
    $("#aspnetForm").attr("target","PagePreview");
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit(); 
}

Here is all the post data I am receiving from the tererik RADEDITOR ::

[ctl00_MainContentPlaceHolder_SideContentRadEditor_dialogOpener_Window_ClientState] => [ctl00_MainContentPlaceHolder_SideContentRadEditor_dialogOpener_ClientState] => [ctl00$MainContentPlaceHolder$SideContentRadEditor] => [ctl00_MainContentPlaceHolder_SideContentRadEditor_ClientState] => [ctl00_MainContentPlaceHolder_ContentRadEditor_dialogOpener_Window_ClientState] => [ctl00_MainContentPlaceHolder_ContentRadEditor_dialogOpener_ClientState] => [ctl00$MainContentPlaceHolder$ContentRadEditor] => %3cp%3eTestPageContent%3c/p%3e 

This is the html value of the text editor (shown above) %3cp%3eTestPageContent%3c/p%3e
This is the value in the RadEditor that was loaded during the Page_Load event.

I changed the value to "Test". But it was not sent over the POST Request, it sent what was loaded in the page load.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

錯遇了你 2024-12-14 05:04:53

编辑器内容区域与用于在 POST 请求期间提交内容的文本区域分开。提交表单时,编辑器将自动尝试将内容保存在隐藏文本区域中,但在您的情况下,不会触发任何事件,因为它以编程方式发生(即您调用 .submit())。您需要告诉编辑器在进行回发之前手动保存其内容。代码非常基本 - 获取对编辑器的引用并调用 .saveContent():

//Grab a reference to the editor
var editor = $find("<%=theEditor.ClientID%>");

//Store the content in the hidden textarea so it can be posted to the server
editor.saveContent();

The editor content area is separate from the textarea used to submit the content during a POST request. The editor will automatically try to save the content in the hidden textarea when the form is submitted, but in your case no event is fired because it happens programmatically (i.e. you call .submit()). You will need to tell the editor to save its content manually before you do the postback. The code is pretty basic - get a reference to the editor and call .saveContent():

//Grab a reference to the editor
var editor = $find("<%=theEditor.ClientID%>");

//Store the content in the hidden textarea so it can be posted to the server
editor.saveContent();
醉态萌生 2024-12-14 05:04:53

一种解决方案是在 showPreview 方法中获取编辑器中的当前 HTML 并手动传递。为此,请在页面中添加一个隐藏的输入元素来保存 HTML 内容:

<input type="hidden" id="htmlContent" name="htmlContent" />

然后,您可以在 showPreview 中设置该 input 的值,如下所示:

function showPreview()
{
    url = "<%= (SiteManager.GetSite()).Url  + this.Filename %>?preview=true"; 
    var specs = "width=1010,height=700,location=0,resizeable=1,status=1,scrollbars=1"; 
    window.open(url, 'PagePreview', specs).moveTo(25, 25);
    $("#__VIEWSTATE").remove();
    $("#__EVENTTARGET").remove();
    $("#__EVENTARGUMENT").remove();

    //   *** Begin New Code ***
    //Grab a reference to the editor
    var editor = $find("<%=theEditor.ClientID%>");

    //Get the current HTML content
    var html = editor.get_html()

    //Put that HTML into this input so it will get posted
    $("#htmlContent").val(html);
    //    *** End New Code ***

    $("#aspnetForm").removeAttr("action");
    $("#aspnetForm").attr("target","PagePreview");
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit(); 
}

然后,当您想要在回发你可以只使用 Request.Form["htmlContent"]

一个警告:由于你将发布原始 HTML,ASP.NET 的 请求验证可能会导致问题。该验证的主要目的之一是确保 HTML 内容不会被发送回服务器 - 这正是您想要完成的事情。您当然可以关闭验证(请参阅上面的链接),但验证的存在是有原因的。另一种解决方案可能是在发布 HTML 之前对其进行一些基本编码。如果您在发布之前将所有小于号 (<) 替换为某些内容,ASP.Net 会很高兴。然后您只需在回发期间“取消替换”它即可。

One solution would be to grab the current HTML in the editor in your showPreview method and pass that manually. To do that, add a hidden input element in your page to hold the HTML content:

<input type="hidden" id="htmlContent" name="htmlContent" />

Then, you can set that intput's value in showPreview like this:

function showPreview()
{
    url = "<%= (SiteManager.GetSite()).Url  + this.Filename %>?preview=true"; 
    var specs = "width=1010,height=700,location=0,resizeable=1,status=1,scrollbars=1"; 
    window.open(url, 'PagePreview', specs).moveTo(25, 25);
    $("#__VIEWSTATE").remove();
    $("#__EVENTTARGET").remove();
    $("#__EVENTARGUMENT").remove();

    //   *** Begin New Code ***
    //Grab a reference to the editor
    var editor = $find("<%=theEditor.ClientID%>");

    //Get the current HTML content
    var html = editor.get_html()

    //Put that HTML into this input so it will get posted
    $("#htmlContent").val(html);
    //    *** End New Code ***

    $("#aspnetForm").removeAttr("action");
    $("#aspnetForm").attr("target","PagePreview");
    $("#aspnetForm").attr("action", url);
    $("#aspnetForm").submit(); 
}

Then when you want to get the HTML during the postback you can just use Request.Form["htmlContent"]

One caveat: Since you'll be posting raw HTML, ASP.NET's Request Validation might cause problems. One of the major purposes of that validation is to make sure that HTML content doesn't get posted back to the server - the very thing you're trying to accomplish. You could of course turn the validation off (see the link above) but the validation is there for a reason. Another solution might be to do some basic encoding of the HTML before you post it. If you just replace all less-than symbol (<) with something before posting it, ASP.Net will be happy. Then you just need to 'un-replace' it during the postback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文