|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
progress indicator long running proc NO Button clickI need to show iframe with just a graphic (bouncing ball) inside the procedure and before end of procedure close the window I know there are more complicated solutions for a progress bar but I haave spent 2 weeks and I cannot get them to work I have a test form, click a button enter a procedure show the iframe and with click of second button set parent div with iframe in it display to none show then none I cannot understand why on the close I get the javascript error Microsoft JScript runtime error: Object required on line <script language ="javascript"> parent.document.getElementById("cont").style.display = "none"; which is the script that executes in close the code behind is protected void Page_Load(object sender, EventArgs e) { AddClientScript(); } protected void AddClientScript() { const string scriptName = "CALL_POPUP"; StringBuilder sb = new StringBuilder(""); sb.Append("\n<script language =\"javascript\">"); sb.Append("\nlast_id = \"\";"); sb.Append("\nfunction frame_pop(id, oLeft, oTop, oPage)"); sb.Append("\n{"); sb.Append("\nvar mystr = window.showModalDialog('Popframe.aspx');"); sb.Append("\nif (undefined != mystr)"); sb.Append("\n{"); sb.Append("\ndocument.getElementById(\"my_iframe\").style.width = parseInt(document.getElementById(\"cont\").style.width);"); sb.Append("\ndocument.getElementById(\"my_iframe\").style.height = parseInt(document.getElementById(\"cont\").style.height);"); sb.Append("\n}"); sb.Append("\nif (id != last_id) {"); sb.Append("\ndocument.getElementById(\"cont\").style.display = \"block\";"); sb.Append("\ndocument.getElementById(\"cont\").style.left = oLeft;"); sb.Append("\ndocument.getElementById(\"cont\").style.top = oTop;"); sb.Append("\nwindow.frames[\"my_iframe\"].location = oPage;"); sb.Append("\nlast_id = id;"); sb.Append("\n}"); sb.Append("\nelse {"); sb.Append("\ndocument.getElementById(\"cont\").style.display = \"none\";"); sb.Append("\nlast_id = \"\";"); sb.Append("\n}"); sb.Append("\nreturn false;"); sb.Append("\n}"); sb.Append("\n</script>"); if (!ClientScript.IsClientScriptBlockRegistered(scriptName)) //ClientScript.RegisterStartupScript(typeof(Page), scriptName, sb.ToString()); ClientScript.RegisterClientScriptBlock(typeof(Page), scriptName, sb.ToString()); } public static void OpenProgressBar(System.Web.UI.Page Page) { StringBuilder sbScript = new StringBuilder(); sbScript.Append("\n<script language =\"javascript\">"); sbScript.Append(" \n"); sbScript.Append("\nvar newwindow = window.open('page1.aspx', 'name', 'height=200,width=300,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');"); sbScript.Append("\n</script>"); Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString()); } public static void CloseProgressBar(System.Web.UI.Page Page) { StringBuilder sbScript = new StringBuilder(); sbScript.Append("\n<script language =\"javascript\">"); sbScript.Append("\nparent.document.getElementById(\"cont\").style.display = \"none\";"); sbScript.Append("\n</script>"); Page.RegisterClientScriptBlock("CloseProgressBar", sbScript.ToString()); } protected void Button1_Click(object sender, EventArgs e) { BindData(); } protected void BindData() { OpenProgressBar(this.Page); } protected void BindData2() { CloseProgressBar(this.Page); } protected void Button2_Click(object sender, EventArgs e) { BindData2(); } the form is <form id="form1" runat="server"> <div runat="server" id="cont" style="position:absolute;left:300px;top:200px;width:300px;height:140px;display:none;border:1px solid #000000"> <div runat="server" id="pop" style="text-align:center;background-color:#FFFFFF"> </div> <iframe id="my_iframe" name="my_iframe" src="" frameborder="0"></iframe> </div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="open" /> <asp:Button ID="Button2" runat="server" Text="close" onclick="Button2_Click" /> </form> -- cindy "cindy" wrote
> I cannot understand why on the close I get the javascript error In your code where you're generating the JavaScript, you need to use > > Microsoft JScript runtime error: Object required > on line > <script language ="javascript"> > parent.document.getElementById("cont").style.display = "none"; > which is the script that executes in close cont.ClientId instead of "cont": sb.AppendFormat("\ndocument.getElementById(\"{0}\").style.display = \"block\";", cont.ClientId); because when you put runat="server" in the div, it alters the ID when it renders the HTML. Just look at the source and you'll see what I mean. Andrew Still get object not found, I do not need runat for div so I simplifed the form
<form id="form1" runat="server"> <div id="cont" style="position:absolute;left:300px;top:200px;width:300px;height:140px;display:none;border:1px solid #000000"> <div id="pop" style="text-align:center;background-color:#FFFFFF"> </div> <iframe id="my_iframe" name="my_iframe" src="" frameborder="0"></iframe> </div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="open" /> <asp:Button ID="Button2" runat="server" Text="close" onclick="Button2_Click" /> </form> I commented out the line in the close created by javascript to use your suggestion but maybe I have syntax wrong //sbScript.Append("\nparent.document.getElementById(\"cont\").style.display = \"none\";"); sbScript.AppendFormat("\ndocument.getElementById(\"cont.ClientId\").style.display = \"none\";"); I looked in the source created below and I see <div id="cont" <script type="text/javascript"> //Realised by Apachejeff //www.huntingground.freeserve.co.uk last_id = "" function frame_pop(id, oLeft, oTop, oPage) { document.getElementById("my_iframe").style.width = parseInt(document.getElementById("cont").style.width) document.getElementById("my_iframe").style.height = parseInt(document.getElementById("cont").style.height) if (id != last_id) { document.getElementById("cont").style.display = "block" document.getElementById("cont").style.left = oLeft document.getElementById('cont').style.top = oTop window.frames["my_iframe"].location = oPage setTimeout('document.getElementById("headertxt").innerHTML=window["my_iframe"].document.title', 200) last_id = id } else { document.getElementById('cont').style.display = "none" last_id = "" } return false } </script> <body> <form name="form1" method="post" action="index.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTg3NjE0NDI3MmRk6v0m9Bx5KGf3D6sGA3/cnza95QY=" /> </div> <script language ="javascript"> var newwindow = window.open('page1.aspx', 'name', 'height=200,width=300,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no'); </script> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKC8enKDAKM54rGBgK7q7GGCKC1w3Vx0StuMtnTanzYGpzKBaEi" /> </div> <div id="cont" style="position:absolute;left:300px;top:200px;width:300px;height:140px;display:none;border:1px solid #000000"> <div id="pop" style="text-align:center;background-color:#FFFFFF"> </div> <iframe id="my_iframe" name="my_iframe" src="" frameborder="0"></iframe> </div> <input type="submit" name="Button1" value="open" id="Button1" /> <input type="submit" name="Button2" value="close" id="Button2" /> </form> </body> </html> here is the codebehind that creates the javascript see above in source public static void OpenProgressBar(System.Web.UI.Page Page) { StringBuilder sbScript = new StringBuilder(); sbScript.Append("\n<script language =\"javascript\">"); sbScript.Append(" \n"); sbScript.Append("\nvar newwindow = window.open('page1.aspx', 'name', 'height=200,width=300,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');"); sbScript.Append("\n</script>"); Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString()); } public static void CloseProgressBar(System.Web.UI.Page Page) { StringBuilder sbScript = new StringBuilder(); sbScript.Append("\n<script language =\"javascript\">"); //sbScript.Append("\nparent.document.getElementById(\"cont\").style.display = \"none\";"); sbScript.AppendFormat("\ndocument.getElementById(\"cont.ClientId\").style.display = \"none\";"); sbScript.Append("\n</script>"); Page.RegisterClientScriptBlock("CloseProgressBar", sbScript.ToString()); } protected void Button1_Click(object sender, EventArgs e) { BindData(); } protected void BindData() { OpenProgressBar(this.Page); } protected void BindData2() { CloseProgressBar(this.Page); } protected void Button2_Click(object sender, EventArgs e) { BindData2(); } -- Show quoteHide quotecindy "Andrew Morton" wrote: > "cindy" wrote > > I cannot understand why on the close I get the javascript error > > > > Microsoft JScript runtime error: Object required > > on line > > <script language ="javascript"> > > parent.document.getElementById("cont").style.display = "none"; > > which is the script that executes in close > > In your code where you're generating the JavaScript, you need to use > cont.ClientId instead of "cont": > > sb.AppendFormat("\ndocument.getElementById(\"{0}\").style.display = > \"block\";", cont.ClientId); > > because when you put runat="server" in the div, it alters the ID when it > renders the HTML. Just look at the source and you'll see what I mean. > > Andrew > > "cindy" wrote
> Still get object not found, I do not need runat for div so I simplifed the Can you install Firefox and use the Firebug add-on to investigate the DOM?> form Other examples I've seen (e.g. http://www.sitepoint.com/forums/showthread.php?t=177654) suggest what you're doing is right. Andrew I have to install Firefox on another machine and move the application and
install .net and add the addon to debug? How about any link to any demo using the show and close iframe using javascript in the code behind -- Show quoteHide quotecindy "Andrew Morton" wrote: > "cindy" wrote > > Still get object not found, I do not need runat for div so I simplifed the > > form > > Can you install Firefox and use the Firebug add-on to investigate the DOM? > > Other examples I've seen (e.g. > http://www.sitepoint.com/forums/showthread.php?t=177654) suggest what you're > doing is right. > > Andrew > > "cindy" wrote
> I have to install Firefox on another machine and move the application and Is there any reason not to install Firefox on your dev machine? In VS, you > install .net and add the addon to debug? can right-click on an .aspx file and choose which browser to open it with. Or if you run the app in IIS (this may be another can of worms) instead of the web server that comes with VS, you could easily access it from another PC. It's often a good idea to check web sites in other browsers anyway, unless you have a defined target audience. > How about any link to any demo using the show and close iframe using I haven't seen one, but as long as your generated JS looks the same as the > javascript in the code behind other googleable communicating-from-an-iframe-to-its-parent scripts, I don't see why it won't work - unless there's something awry with where in the DOM you should be pointing it to or there's some security thing in the browser preventing communication out from the iframe , but I thought the latter only applied to iframe content from a different domain. http://www.google.com/#hl=en&q=iframe+parent+javascript Does anyone else want to chime in? Andrew "cindy" <cmello@nospam.nospam> wrote in message No you don't.news:8FF72825-5DB9-4306-BCFB-7BE636803AFE@microsoft.com... > I have to install FireFox on another machine and move the application and > install .net and add the addon to debug? In order to debug dynamically-generated client-side JavaScript like this inside Visual Studio.NET, you will need to use the debugger; keyword at the top of the JavaScript routine that you intend to debug. So long as you're running the web app in Debug mode, the code should break at that line: http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx However, another major problem is: "I have a procedure long running in C# asp.net 2003 app" - mainstream support for Visual Studio.NET 2003 ended last year, and I'm guessing you haven't purchased an extended support contract as these are very expensive: http://support.microsoft.com/lifecycle/search/default.aspx?sort=PN&alpha=Visual+Studio+.NET+2003&Filter=FilterNO Time to upgrade... > sbScript.Append("\n<script language =\"javascript\">"); The language property of the <script /> tag has been deprecated for nearly thirteen years now! Replace all instances of the above with: sbScript.Append("\n<script type =\"text/javascript\">"); Or, even better, once you upgrade to a more recent (and still supported!) version of Visual Studio.NET, you can then use the boolean overload of RegisterClientScriptBlock which will get Visual Studio.NET to generate the script tags for you automatically... Upgraded to 2008, the app is two forms the code is all on this post
Use the .net debugger and I break on the line Microsoft JScript runtime error: Object required on line <script language ="javascript"> parent.document.getElementById("cont").style.display = "none"; which is the script that executes in close the code behind is protected void Page_Load(object sender, EventArgs e) { AddClientScript(); } protected void AddClientScript() { const string scriptName = "CALL_POPUP"; StringBuilder sb = new StringBuilder(""); sb.Append("\n<script language =\"javascript\">"); sb.Append("\nlast_id = \"\";"); sb.Append("\nfunction frame_pop(id, oLeft, oTop, oPage)"); sb.Append("\n{"); sb.Append("\nvar mystr = window.showModalDialog('Popframe.aspx');"); sb.Append("\nif (undefined != mystr)"); sb.Append("\n{"); sb.Append("\ndocument.getElementById(\"my_iframe\").style.width = parseInt(document.getElementById(\"cont\").style.width);"); sb.Append("\ndocument.getElementById(\"my_iframe\").style.height = parseInt(document.getElementById(\"cont\").style.height);"); sb.Append("\n}"); sb.Append("\nif (id != last_id) {"); sb.Append("\ndocument.getElementById(\"cont\").style.display = \"block\";"); sb.Append("\ndocument.getElementById(\"cont\").style.left = oLeft;"); sb.Append("\ndocument.getElementById(\"cont\").style.top = oTop;"); sb.Append("\nwindow.frames[\"my_iframe\"].location = oPage;"); sb.Append("\nlast_id = id;"); sb.Append("\n}"); sb.Append("\nelse {"); sb.Append("\ndocument.getElementById(\"cont\").style.display = \"none\";"); sb.Append("\nlast_id = \"\";"); sb.Append("\n}"); sb.Append("\nreturn false;"); sb.Append("\n}"); sb.Append("\n</script>"); if (!ClientScript.IsClientScriptBlockRegistered(scriptName)) //ClientScript.RegisterStartupScript(typeof(Page), scriptName, sb.ToString()); ClientScript.RegisterClientScriptBlock(typeof(Page), scriptName, sb.ToString()); } public static void OpenProgressBar(System.Web.UI.Page Page) { StringBuilder sbScript = new StringBuilder(); sbScript.Append("\n<script language =\"javascript\">"); sbScript.Append(" \n"); sbScript.Append("\nvar newwindow = window.open('page1.aspx', 'name', 'height=200,width=300,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');"); sbScript.Append("\n</script>"); Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString()); } public static void CloseProgressBar(System.Web.UI.Page Page) { StringBuilder sbScript = new StringBuilder(); sbScript.Append("\n<script language =\"javascript\">"); sbScript.Append("\nparent.document.getElementById(\"cont\").style.display = \"none\";"); sbScript.Append("\n</script>"); Page.RegisterClientScriptBlock("CloseProgressBar", sbScript.ToString()); } protected void Button1_Click(object sender, EventArgs e) { BindData(); } protected void BindData() { OpenProgressBar(this.Page); } protected void BindData2() { CloseProgressBar(this.Page); } protected void Button2_Click(object sender, EventArgs e) { BindData2(); } the form is <form id="form1" runat="server"> <div id="cont" style="position:absolute;left:300px;top:200px;width:300px;height:140px;display:none;border:1px solid #000000"> <div id="pop" style="text-align:center;background-color:#FFFFFF"> </div> <iframe id="my_iframe" name="my_iframe" src="" frameborder="0"></iframe> </div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="open" /> <asp:Button ID="Button2" runat="server" Text="close" onclick="Button2_Click" /> </form> -- Show quoteHide quotecindy -- cindy "Mark Rae [MVP]" wrote: > "cindy" <cmello@nospam.nospam> wrote in message > news:8FF72825-5DB9-4306-BCFB-7BE636803AFE@microsoft.com... > > > I have to install FireFox on another machine and move the application and > > install .net and add the addon to debug? > > No you don't. > > In order to debug dynamically-generated client-side JavaScript like this > inside Visual Studio.NET, you will need to use the debugger; keyword at the > top of the JavaScript routine that you intend to debug. So long as you're > running the web app in Debug mode, the code should break at that line: > http://blogs.msdn.com/ie/archive/2004/10/26/247912.aspx > > However, another major problem is: "I have a procedure long running in C# > asp.net 2003 app" - mainstream support for Visual Studio.NET 2003 ended last > year, and I'm guessing you haven't purchased an extended support contract as > these are very expensive: > http://support.microsoft.com/lifecycle/search/default.aspx?sort=PN&alpha=Visual+Studio+.NET+2003&Filter=FilterNO > Time to upgrade... > > > > sbScript.Append("\n<script language =\"javascript\">"); > > The language property of the <script /> tag has been deprecated for nearly > thirteen years now! Replace all instances of the above with: > sbScript.Append("\n<script type =\"text/javascript\">"); > > Or, even better, once you upgrade to a more recent (and still supported!) > version of Visual Studio.NET, you can then use the boolean overload of > RegisterClientScriptBlock which will get Visual Studio.NET to generate the > script tags for you automatically... > > > -- > Mark Rae > ASP.NET MVP > http://www.markrae.net > > "cindy" <cmello@nospam.nospam> wrote in message Please read my previous reply...news:BA9D9E8B-7026-496D-B155-5F3FC2A40920@microsoft.com... > <script language ="javascript"> cindy wrote
> Microsoft JScript runtime error: Object required OK, a little bit of testing suggests that you can't do that with an > on line > <script language ="javascript"> > parent.document.getElementById("cont").style.display = "none"; > which is the script that executes in close <iframe>. Just enclose it in a <div> and set the display style on that. -- this is page.html <html> <head> <title>Testing iframe communication</title> <script type="text/javascript"> function show_iframe() { document.getElementById("my_iframe_container").style.display="block"; } </script> </head> <body> <p onclick="show_iframe()">Show iframe</p> <div id="my_iframe_container" style="display:none"> <iframe id="my_iframe" src="my_iframe.html" /> </div> </body> </html> -- this is my_iframe.html <html> <head> <title>x</title> <script type="text/javascript"> function hi() { parent.document.getElementById('my_iframe_container').style.display='none'; } </script> </head> <body> <p onclick="hi()" style="background-color:Red">Hide me</p> </body> </html> You really should have tried an absolutely minimal amount of markup to test it - I know all too well that sometimes one can get too engrossed in some part of something to widen/narrow one's view to be able to focus on the pertinent items. HTH, Andrew Andrew Morton wrote:
> cindy wrote Pah! Silly me. Re-reading your original post I notice that /is/ what you're >> Microsoft JScript runtime error: Object required >> on line >> <script language ="javascript"> >> parent.document.getElementById("cont").style.display = "none"; >> which is the script that executes in close > > OK, a little bit of testing suggests that you can't do that with an > <iframe>. Just enclose it in a <div> and set the display style on > that. doing. Although your code is a bit obscure to me (e.g. you have a method BindData2() which appears to have nothing to do with binding data), I think that what you're trying to do is have your code-behind interact with the browser. That doesn't work unless you're using AJAX (or similar). Now you have a later version of VS, you might consider using AJAX to give a progress bar. Here is an article with code: http://www.4guysfromrolla.com/articles/050708-1.aspx Andrew [My reply of a couple of minutes ago hasn't come through to my newsreader
yet.] Oh, and when I tested that in IE8 instead of FF3.5, IE gave a message about blocking scripts; is it possible you've told your IE not to display messages about blocking scripts? Andrew I am using Ajax panels to show progress when a button executes a procedure
“Chart2_Load†to fill a chart. It works. When the page loads initially the chart is filled with a default values and the progress bar does not show during the initial page load, this is also the longest time to wait for the load. protected void Page_Load(object sender, EventArgs e) { if (!(Page.IsPostBack)) { Chart2_Load(TextStart, TextEnd); } } How can I show simple waiting message with Javascript or tell me what I am doing wrong with Ajax to get the user a message during the first page load seen above? I have included the html for the panels below. User requirements are to load the page initial with default values and not ask them to click before chart loads first time. <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <style type="text/css">…….. </style> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="QuarterUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Always"> <ContentTemplate> <asp:DataList id="dlButtons runat="server" /> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="PieUpdatePanel" runat="server" OnLoad="PieUpdatePanel_Load" ChildrenAsTriggers="true" UpdateMode="Always"> <ContentTemplate> <dotnet:Chart id="ChartPie" runat="server"/> </ContentTemplate> </asp:UpdatePanel> <asp:UpdateProgress ID="UpdateProgress1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always"> <ProgressTemplate> <div id="OuterTableCellOverlay"> <div id="InnerTableCellOverlay"> <b>... LOADING ...</b> <asp:Image ID="LoadImage" runat="server" ImageUrl="~/Images/ajax-loader.gif" /> </div> </div> </ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel ID="ChartUpdatePanel" runat="server" OnLoad="ChartUpdatePanel_Load"> <ContentTemplate> <dotnet:Chart id="Chart5" runat="server"/> </ContentTemplate> </asp:UpdatePanel> </form> </body> </html> -- Show quoteHide quotecindy "Andrew Morton" wrote: > [My reply of a couple of minutes ago hasn't come through to my newsreader > yet.] > > Oh, and when I tested that in IE8 instead of FF3.5, IE gave a message about > blocking scripts; is it possible you've told your IE not to display messages > about blocking scripts? > > Andrew > >
Other interesting topics
Help with C# using popup pox
Commented codes still affect the program Web Deployment Project - Publish? Displaying a generated picture in MS Word Image does not fit correctly in a div frame Multiple Select commands Localization issue with master page. Boundfield display value How to get an https url when using Forms and Default login redirect BUG? Repeating tag syntax in VS 2008 source mode...? |
|||||||||||||||||||||||