Note that there are some explanatory texts on larger screens.

plurals
  1. POMy javascript variable is becoming undefined between function calls
    text
    copied!<p>I have a form that calls some javascript and some code behind (C# for me) when a link button is pressed. Normal operation should act as such: Click on link button which gets text from a label on the form, opens an HTML editor, save the text by clicking 'Done' on the text editor and then displaying the text on the form again. It will do all of that, but I get an error (control is undefined) and then that prevents me from doing any other work on the form.</p> <p>First, here is my aspx code, which is a window that hold the HTML editor, and the HTML editor.</p> <pre><code>&lt;asp:Panel ID="EditCommentPopup" runat="server" SkinID="PopupPanel" HorizontalAlign="Center" Width="500px" Style="display:none;"&gt; &lt;div id="SendCommentHeader" class="modalPopupHeader"&gt; &lt;table width="100%" style="vertical-align: middle"&gt; &lt;tr&gt; &lt;td style="width: 50%; text-align: left; padding-left: 5px;"&gt; &lt;asp:Label ID="EditCommentHeaderLBL" runat="server" Font-Bold="true" Text="Change Comment" &gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td style="width: 50%; text-align: right; padding-right: 3px;"&gt; &lt;asp:Button SkinID="SubmitButton" ID="SaveComment" runat="server" Text="Done" OnClientClick="submitEditorPopup(); return true;" OnClick="SubmitCommentButton_Click"/&gt; &lt;asp:Button SkinID="CancelButton" ID="cancelCommentButton" runat="server" Text="Cancel"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;ajaxToolkit:ModalPopupExtender ID="EditCommentPopupExtender" runat="server" TargetControlID="EditCommentHeaderLBL" PopupControlID="EditCommentPopup" BackgroundCssClass="modalBackground" PopupDragHandleControlID="EditCommentPopup" DropShadow="False" CancelControlID="cancelCommentButton" BehaviorID="ChangeCommentsPopup" &gt; &lt;/ajaxToolkit:ModalPopupExtender&gt; &lt;asp:Panel ID="EditCommentInnerPanel" SkinID="PopupInnerPanel" HorizontalAlign="Center" runat="server" &gt; &lt;asp:Label ID="CommandArgLBL" runat="server" Visible="false"&gt;&lt;/asp:Label&gt; &lt;custom:CustomTextEditor ID="EditCommentsTextBox" runat="server" Width="100%" Height="300px" NoScript="true" /&gt; &lt;/asp:Panel&gt; &lt;/asp:Panel&gt; </code></pre> <p>Here are my javascript functions</p> <pre><code>var contentLBL; var editorControl; var hiddenField; function LoadEditorPopup(labelID, editorID, hiddenID, linkID) { editorControl = document.getElementById(editorID); contentLBL = document.getElementById(labelID); hiddenField = document.getElementById(hiddenID); editorControl.control.set_content(contentLBL.innerHTML); var popup = $find("ChangeCommentsPopup"); popup.show(); } function submitEditorPopup() { var tmp = editorControl.control.get_content(); //error flags here contentLBL.innerHTML = tmp; var str= new String(); str = tmp; str = str.replace(/&lt;/g, "{%"); str = str.replace(/&gt;/g, "%}"); //stripping out html tags to prevent sql insertion hiddenField.value = str; var popup = $find("ChangeCommentsPopup"); popup.hide(); } </code></pre> <p>And here are my C# functions</p> <pre><code>protected void ShowEditCommentPopup(object sender, EventArgs e) { string arg = ((LinkButton)sender).CommandArgument; string content = ""; string title = ""; switch (arg) { //doing stuff, setting content and title } EditCommentHeaderLBL.Text = title; CommandArgLBL.Text = arg; EditCommentsTextBox.Content = content; EditCommentPopupExtender.Show(); EditModalPopupExtender.Show(); //this is the form } </code></pre> <p>So, what's happening here, I click on a linkbutton (not shown in aspx code) and it fires the LoadEditorPopup function in the javascript. It does its stuff and I have a 'return true' in the onclientclick call so that the next function, ShowEditCommentPopup, in the code behind, will be called. The editor pops up and I can use it just fine. When I click 'Done' the SubmitEditorPopup event is fired in the javascript and I get an error saying that the variable EditorControl is undefined. I have found that if I do not call the ShowEditCommentPopup method, the error does not occur, but then I get back to another problem I had originally, which I'm hoping that will be fixed if this problem is fixed.</p> <p>I really hope that was clear enough. Thanks in advance!</p>
 

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