Note that there are some explanatory texts on larger screens.

plurals
  1. POCodemirror textarea not working on popup
    primarykey
    data
    text
    <p>I got this working between shifting between 2 aspx pages in C#, but now that I change it into a popup it does not work anymore. It is an xml file which I am trying to show in the codemirror editor. It seems like that javascript is running before the pop is actully made, and there it is taking an empty textarea and rendering the codemirror on. I am not sure though, so hopefully someone is having the solution for me.</p> <p>My view is like this:</p> <pre><code> &lt;script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" type="text/javascript"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/&gt; &lt;link rel="stylesheet" href="&lt;%= Html.IncludeFile("Scripts", "Codemirror/codemirror.css") %&gt;" /&gt; &lt;script type="text/javascript" src="&lt;%= Html.IncludeFile("Scripts", "Codemirror/codemirror.js")%&gt;"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="&lt;%= Html.IncludeFile("Scripts", "Codemirror/xml.js")%&gt;"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function init() { $(document).ready( function () { $("#result").dialog({ autoOpen: false, title: 'Edit the table', width: 500, open: GetXml(), height: 'auto', modal: true }); }); openPopup(); } function openPopup() { $("#result").dialog("open"); } function GetXml() { //var selec = $("Selected").val($("FileName").val()); var Selected = document.getElementById("FileName").value; $.ajax({ type: "POST", url: "GetXmlFile", data: { Selected: $('#FileName').val() } }) .done(function (msg) { // alert("Data Saved: " + msg); $('#File').html(msg); }); } function SaveChanges() { alert('Get the values and post them back to the server to be saved!'); $("#result").dialog("close"); } &lt;/script&gt; &lt;style type="text/css"&gt; .CodeMirror { border:1px solid #334; width:auto; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="result" style="display:none"&gt; &lt;% using (Html.BeginForm("Index","EditFile")) %&gt; &lt;% { %&gt; &lt;%= Html.TextAreaFor(m =&gt; m.File) %&gt; &lt;%= Html.ValidationMessageFor(m =&gt; m.File)%&gt; &lt;input type="submit" value="Save" /&gt; &lt;% } %&gt; &lt;script type="text/javascript"&gt; var editor = CodeMirror.fromTextArea(document.getElementById("File"), { lineNumbers: true, matchBrackets: true, mode: "text/xml" }); &lt;/script&gt; &lt;/div&gt; &lt;table style="width:100%;"&gt; &lt;tr&gt; &lt;td style="width:15px;"&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt; &lt;% using (Html.BeginForm()) %&gt; &lt;% { %&gt; &lt;ul&gt; &lt;li&gt; &lt;%= Html.LabelFor(m =&gt; m.FileName) %&gt; &lt;%=Html.DropDownListFor(m =&gt; m.FileName,new SelectList(System.IO.Directory .EnumerateFiles(@"C:\Something", "*") .Select(System.IO.Path.GetFileNameWithoutExtension)), "Please select one")%&gt; &lt;%=Html.ValidationMessageFor(m =&gt; m.FileName)%&gt; &lt;/li&gt; &lt;/ul&gt; &lt;% } %&gt; &lt;input type="button" onclick="init()" value="open box"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p> </p> <p>The method called in the controller:</p> <pre><code>[HttpPost] public String GetXmlFile(String Selected) { String selectedFileName = @"C:\Something\" + Selected + ".xml"; String line = ""; String[] linesInFile = System.IO.File.ReadAllLines(selectedFileName); foreach (var lines in linesInFile) { line = String.Concat(line, lines + Environment.NewLine); } return line; } </code></pre> <p>Any ideas?</p> <p>If this can't be done, which editor would you then suggest me to use for showing xml and editoring in the file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload