I’m using Microsoft Visual Web Developer 2010 Express.
I have a hidden image button, that is set to visible="true" if the user uploads an image.
Here is the code:
aspx file:
<asp:UpdatePanel ID="upOne" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ImageButton ID="btnImageOne" runat="server" CssClass="btnImage"
Visible="false" onclick="btnImageOne_Click" />
<asp:LinkButton ID="btnDeleteOne" runat="server" CssClass="btnDelete" Visible="false"
onclick="btnDeleteOne_Click"> </asp:LinkButton>
</ContentTemplate>
</asp:UpdatePanel>
When visible, if clicked by the user, the button does:
aspx.cs file:
protected void btnDeleteOne_Click(object sender, EventArgs e)
{
if (Session["fuOneFilename"] != null)
{
File.Delete(Server.MapPath("~/animals/temp/") + (string)Session["fuOneFilename"]);
Session["fuOneFilename"] = null;
DisplayUploadedPictures();
if (Session["mainImageFilename"] == Session["fuOneFilename"])
{
Session["mainImageFilename"] = null;
DisplayMainImage();
}
}
}
I placed a Break Point in the seccond line of the aspx.cs file.
After pressing F5, the application stops in a JavaScript line, located inside the jQuery (unmodified) file.
j = Array.prototype.push
I am presented with the message:
Runtime Error in Microsoft JScript: ‘Array’ is not defined
In the same window, I can see three buttons:
Break, Continue, Ignore.
Note: Break Points in the Page Load run without a problem.
The call stack says:
Anonymous Function JScript
JScript global code JScript
Questions:
Q1. Why is this happening?
Q2. How can I fix it?
Q1. Why is this happening?
This error happens if you have the following configuration:
When the page loads, the panel being shown forces the script inside the iframe to be dragged through the DOM before the javascript libraries are loaded.
Q2. How can I fix it?
The solution is to declare the source attribute through jQuery:
Final Notes:
All credits of this answer go to spender, who pointed me in the right direction with his comment.
However, I didnt want to leave this question “unanswered”, so I decided to gather the info from the linked post and assemble it into a single post.