Telerik RadEditor HTTP POST VALUE 未更新(ASP.NET Web 表单)
我目前正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑器内容区域与用于在 POST 请求期间提交内容的文本区域分开。提交表单时,编辑器将自动尝试将内容保存在隐藏文本区域中,但在您的情况下,不会触发任何事件,因为它以编程方式发生(即您调用 .submit())。您需要告诉编辑器在进行回发之前手动保存其内容。代码非常基本 - 获取对编辑器的引用并调用 .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():
一种解决方案是在
showPreview
方法中获取编辑器中的当前 HTML 并手动传递。为此,请在页面中添加一个隐藏的输入元素来保存 HTML 内容:然后,您可以在 showPreview 中设置该
input
的值,如下所示:然后,当您想要在回发你可以只使用
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:Then, you can set that
intput
's value in showPreview like this: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.