인사말!UpdatePanel의 "Preview Area"가 새로 고침되지 않습니다.
사용자가 다양한 라디오 버튼을 선택하고 일부 데이터를 표시하기 위해 페이지에서 사용할 수있는 HTML 태그 (주로 SCRIPT 태그)를 생성하는 "코드 작성기"페이지가 있습니다. "미리보기"영역이있어서 사이트에서 코드를 복사/붙여 넣기 전에 결과를 볼 수 있습니다. 양식은 FormView 컨트롤에 존재하고 그래서 같은 UpdatePanel에 의해 싸여있다 :
<script src="http://example.com/src/Constants.js"></script>
<script>
showIPAddress = 0;
DisplayServerStatus();
</script>
: 다음과 같이 보일 수있는, 그것은 성공적으로 copycode 텍스트 상자에있는 코드를 생성
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataSourceId="XmlDataSource1">
<ItemTemplate>
<div id="configArea">
<ul>
<li>
<%# XPath("Steps/Step1/ServerStatus") %><br />
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="OneA" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="OneA" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/Uptime") %><br />
<asp:RadioButton ID="RadioButton3" runat="server" GroupName="OneB" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton4" runat="server" GroupName="OneB" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
<li>
<%# XPath("Steps/Step1/IPAddress") %><br />
<asp:RadioButton ID="RadioButton5" runat="server" GroupName="OneC" Checked="true" AutoPostBack="true" Text='<%# XPath("Steps/Step1/YesOption") %>' />
<asp:RadioButton ID="RadioButton6" runat="server" GroupName="OneC" AutoPostBack="true" Text='<%# XPath("Steps/Step1/NoOption") %>' />
</li>
</ul>
</div>
<div id="copyCode">
<%# XPath("Steps/Step2/CopyPasteCode") %><br />
<asp:TextBox ID="Textbox1" runat="server" TextMode="MultiLine" Width="300" Height="300" />
</div>
<div id="previewArea">
<%# XPath("Steps/Step3/PreviewTitle") %><br />
<asp:Literal ID="Literal1" runat="server" />
</div>
</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="Root/Data" />
(TextBox1에) 동시에 "미리보기"영역의 리터럴 컨트롤 (Literal1)을 텍스트 상자 (TextBox1)의 텍스트로 업데이트합니다. 미리보기는 UpdatePanel 내부에 있지 않을 때 완벽하게 표시되지만 그럴 때는 작동하지 않습니다. 그리고 페이지 새로 고침을 방지하기 위해 UpdatePanel을 사용하고 싶습니다. 내가 PreRender 이벤트 중에 "미리보기"영역 및 copycode 텍스트의 업데이트를 수행합니다 그것이 UpdatePanel에 때
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
UpdateCodeSnippetAndPreviewArea();
}
모든 아이디어를 왜 미리보기가 업데이트되지 않습니다?
마지막 문장까지 계속됩니다. 정교하게 제발 주시겠습니까? – Bullines
예를 들어 JQuery를 사용하여 서버에서 반환 된 내용을 다시 구문 분석하고 모든 스크립트가로드/실행되는지 확인할 수 있습니다. 이것은 자신의 도우미 기능을 스크립팅하지 않고도 문제를 해결할 수있는 가장 쉬운 방법입니다. say = 'test'라고 쓰면 컨테이너에 리터럴을 넣을 수 있습니다. 그런 다음 서버 측에서 : ScriptManager.RegisterStartUpScript (UpdatePanel1, UpdatePanel1.GetType(), "mytest", "$ ('# test') .html ($ ('# test') .html());", 참된); 이것은 컨테이너의 innerHTML을 찾아서 다시 구문 분석하고 이번에는 모든 스크립트를 실행하는 것을 제외하고 원래의 위치로 다시 주입합니다. 희망이 도움이됩니다. – Rohland
이것이 jQuery 없이도 가능합니까? – Bullines