本文介绍了Javascript工作正常,直到按下asp.net按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我也在asp.net组上发布了这个。我不确定这是一个 asp.net问题还是一个javascript问题。 我有一个最初是从程序创建的页面我在网上找到了 ,它可以很好地用作html页面。 它会打开一个模态弹出窗口,我一直试图为 天现在,这是我能够来的最近的。 我添加了一个小的asp.net代码和一个asp.net按钮,无法获得 使用该按钮。它似乎打破了javascript代码。 无论是否使用asp.net代码页面都能正常工作(只要asp.net 按钮是没推过。 这个工作正常(和以前一样),直到我按下asp.net按钮。我打开 各个位置的警报框,直到asp.net按钮被推送为。从那时起,所有链接和按钮都会在第一个javascript函数中显示警告框 ,但ModalDialogShow永远不会被称为 或它只是忽略它,因此弹出窗口永远不会被调用。 为什么asp.net按钮会导致Javascript退出运行? 为什么弹出窗口没有按下按钮或链接时关闭 他们? ******************* ******************************* ******************* ***************** <%@ Page Language =" VB"跟踪= QUOT假QUOT;调试= QUOT;真" AutoEventWireup =" true" ContentType =" text / html"的ResponseEncoding = QUOT; ISO-8859-1" %> < html> < script language = JavaScript> var ModalDialogWindow; var ModalDialogInterval; var ModalDialog = new Object; ModalDialog.value =''''; ModalDialog .eventhandler =''''; 函数ModalDialogMaintainFocus() { 试试 { if(ModalDialogWindow.closed) { alert(" at ModalDialogWindow.closed"); window.clearInterval (ModalDialogInterval); eval(ModalDialog.eventhandler); 返回; } ModalDialogWindow.focus( ); } catch(一切){} } 函数ModalDialogRemoveWatch() { ModalDialog.value =''''; ModalDialog.eventhandler =''''; } 函数ModalDialogShow(Title,BodyText,Buttons,EventHandle r) { alert("在ModalDialogShow中); ModalDialogRemoveWatch(); ModalDialog.eventhandler = EventHandler; var args =''width = 350,height = 125,left = 325,top = 300,toolba r = 0,''; args + =''location = 0,status = 0,menubar = 0,scrollbars = 1,resizable = 0''; ModalDialogWindow = window.open("","",args) ; ModalDialogWindow.document.open(); ModalDialogWindow.document.write(''< html>''); ModalDialogWindow .document.write(''< head>''); ModalDialogWindow.document.write(''< title>''+ Title +''< / title>'') ; ModalDialogWindow.document.write(''< script''+''language = JavaScript>''); ModalDialogWindow.document.write(''function CloseForm(Response)''); ModalDialogWindow.document.write(''{''); ModalDialogWindow.document.w rite(''window.opener.ModalDialog.value = 回应; ''); ModalDialogWindow.document.write(''window.close();''); ModalDialogWindow.document.write(''}'') ; ModalDialogWindow.document.write(''< / script''+''>''); ModalDialogWindow.document.write(''< / head>''); ModalDialogWindow.document.write(''< body onblur =" window.focus();">''); ModalDialogWindow.document.write(''< table border = 0 width =" 95%" align = center cellspacing = 0 cellpadding = 2>''); ModalDialogWindow.document.write(''< tr>< td align = left>''+ BodyText + ''< / td>< / tr>'' ); ModalDialogWindow.document.write(''< tr>< td align = left>< br>< / td>< / tr>''); ModalDialogWindow.document.write(''< tr>< td align = center>''+ Buttons + ''< / td>< / tr>' '); ModalDialogWindow.document.write(''< / body>''); ModalDialogWindow.document.write(''< / html>''); ModalDialogWindow.document.close(); ModalDialogWindow.focus(); ModalDialogInterval = window.setInterval(" ModalDialogMaintainFocus()",5); } < / script> < script language = JavaScript> 函数YesNoCancel(BodyText,EventHandler) { alert(在YesNoCancel内部) var Buttons =''' '; // Buttons =''< a href = javascript :CloseForm("是");> Yes< / a> ''; // Buttons + =''< a href = javascript :CloseForm(" No");> No< / a> ''; // Buttons + =''< a href = javascript :CloseForm(" Cancel");> Cancel< / a> ''; Buttons =''< BUTTON onclick =" javascript :CloseForm(\''是'\\''');" type =" button">是< / BUTTON> ''; 按钮+ =''< BUTTON onclick =" javascript :CloseForm(\''No \'');" type = " button"> No< / BUTTON> ''; 按钮+ =''< BUTTON onclick =" javascript :CloseForm(\''Cancel \'');" type = " button">取消< / BUTTON> ''; ModalDialogShow(" Dialog",BodyText,Buttons,EventHan dler); } 功能YesNoMaybe( BodyText,EventHandler) { var Buttons =''''; Buttons =''< a href = javascript :CloseForm(QUOT;是");>是< / A> ''; 按钮+ =''< a href = javascript :CloseForm(" No");> No< / a> ''; 按钮+ =''< a href = javascript :CloseForm(" Maybe");>可能< / a> ''; ModalDialogShow(" Dialog",BodyText,Buttons,EventHan dler); } 函数YesNoCancelReturnMethod( ) { alert("在YesNoCancelReturnMethod内); document.getElementById(''modalreturn1'')。value = ModalDialog。价值; ModalDialogRemoveWatch(); } 函数YesNoMaybeReturnMethod() { document.getElementById(''modalreturn2'')。value = ModalDialog.value; ModalDialogRemoveWatch(); } < / script> < script runat =" server"> sub page_load(s as object,e as eventArgs) 如果不是isPostBack那么 Button1.Attributes.Add(" onclick"," YesNoCancel(''是,不,或取消 me'',''YesNoCancelReturnMethod()'');") 结束如果 end sub < / script> &l t; BODY> < table border = 1 cellpadding = 2 cellspacing = 2 align = center width =" 60%"> < tr>< td align = left>< / td>< / tr> < tr>< td align = left>< / td>< / tr> < tr>< td align = left>< / td>< / tr> < tr> < ; td align = left>< a href =" javascript :YesNoCancel(''是,不,或取消 me'',''YesNoCancelReturnMethod()' ');">显示模态#1< / a> 1.< input type = text id = modalreturn1 name = modalreturn1 value =''' '>< / td> < / tr> < tr> < td align = left>< a href =" javascript :YesNoMaybe(''是,不,或者可能 我'',''YesNoMaybeReturnMethod()'');">显示模态#2< / a> 2.< input type = text id = modalreturn2 name = modalreturn2 value =''''>< / td> < / tr> < tr> < td> < BUTTON onclick =" javascript :YesNoMaybe(''是,不,或者可能 me'',''YesNoMaybeReturnMethod()'');" type =" button">打开子窗口< / BUTTON> < / td> < / tr> < ; / table> < form runat =" server"> < asp:Button ID =" Button1"文本= [提交" runat =" server" /> < / form> < / BODY> < / HTML> ******************************************** ****** ************************************** * 谢谢, TomI posted this on the asp.net group, also. I wasn''t sure whether this was anasp.net problem or a javascript problem.I have a page that was originally created from a program I found on the netthat works well as an html page.It brings up a modal popup window that I have been trying to work out fordays now and this was the closest I have been able to come.I added a little asp.net code and an asp.net button and cannot get it towork with that button. It seems to break the javascript code.The page works fine with or without the asp.net code (as long as the asp.netbutton is not pushed).This works fine (as before) until I press the asp.net button. I am openingalert boxes in various locations that all fire until the asp.net button ispushed. From that time, all links and buttons will bring up the alert boxin the first javascript funtion, but the ModalDialogShow never gets calledor it just ignores it and therefore the popup window never gets called.Why would the asp.net button cause the Javascript to quit functioning?Why does the popup window not close when the buttons or links are pressed onthem?************************************************** ************************************<%@ Page Language="VB" trace="false" debug="true" AutoEventWireup="true"ContentType="text/html" ResponseEncoding="iso-8859-1" %><html><script language=JavaScript>var ModalDialogWindow;var ModalDialogInterval;var ModalDialog = new Object;ModalDialog.value = '''';ModalDialog.eventhandler = '''';function ModalDialogMaintainFocus(){try{if (ModalDialogWindow.closed){alert("at ModalDialogWindow.closed");window.clearInterval(ModalDialogInterval);eval(ModalDialog.eventhandler);return;}ModalDialogWindow.focus();}catch (everything) { }}function ModalDialogRemoveWatch(){ModalDialog.value = '''';ModalDialog.eventhandler = '''';}function ModalDialogShow(Title,BodyText,Buttons,EventHandle r){alert("inside ModalDialogShow");ModalDialogRemoveWatch();ModalDialog.eventhandler = EventHandler;var args=''width=350,height=125,left=325,top=300,toolba r=0,'';args+=''location=0,status=0,menubar=0,scrollbars=1, resizable=0'';ModalDialogWindow=window.open("","",args);ModalDialogWindow.document.open();ModalDialogWindow.document.write(''<html>'');ModalDialogWindow.document.write(''<head>'');ModalDialogWindow.document.write(''<title>'' + Title + ''</title>'');ModalDialogWindow.document.write(''<script'' + '' language=JavaScript>'');ModalDialogWindow.document.write(''function CloseForm(Response) '');ModalDialogWindow.document.write(''{ '');ModalDialogWindow.document.write('' window.opener.ModalDialog.value =Response; '');ModalDialogWindow.document.write('' window.close(); '');ModalDialogWindow.document.write(''} '');ModalDialogWindow.document.write(''</script'' + ''>'');ModalDialogWindow.document.write(''</head>'');ModalDialogWindow.document.write(''<body onblur="window.focus();">'');ModalDialogWindow.document.write(''<table border=0 width="95%"align=center cellspacing=0 cellpadding=2>'');ModalDialogWindow.document.write(''<tr><td align=left>'' + BodyText +''</td></tr>'');ModalDialogWindow.document.write(''<tr><td align=left><br></td></tr>'');ModalDialogWindow.document.write(''<tr><td align=center>'' + Buttons +''</td></tr>'');ModalDialogWindow.document.write(''</body>'');ModalDialogWindow.document.write(''</html>'');ModalDialogWindow.document.close();ModalDialogWindow.focus();ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",5) ;}</script><script language=JavaScript>function YesNoCancel(BodyText,EventHandler){alert("inside YesNoCancel")var Buttons='''';// Buttons = ''<a href=javascript:CloseForm("Yes");>Yes</a> '';// Buttons += ''<a href=javascript:CloseForm("No");>No</a> '';// Buttons += ''<a href=javascript:CloseForm("Cancel");>Cancel</a> '';Buttons = ''<BUTTON onclick="javascript:CloseForm(\''Yes\'');"type="button">Yes</BUTTON> '';Buttons += ''<BUTTON onclick="javascript:CloseForm(\''No\'');" type ="button">No</BUTTON> '';Buttons += ''<BUTTON onclick="javascript:CloseForm(\''Cancel\'');" type ="button">Cancel</BUTTON> '';ModalDialogShow("Dialog",BodyText,Buttons,EventHan dler);}function YesNoMaybe(BodyText,EventHandler){var Buttons='''';Buttons = ''<a href=javascript:CloseForm("Yes");>Yes</a> '';Buttons += ''<a href=javascript:CloseForm("No");>No</a> '';Buttons += ''<a href=javascript:CloseForm("Maybe");>Maybe</a> '';ModalDialogShow("Dialog",BodyText,Buttons,EventHan dler);}function YesNoCancelReturnMethod(){alert("inside YesNoCancelReturnMethod");document.getElementById(''modalreturn1'').value = ModalDialog.value;ModalDialogRemoveWatch();}function YesNoMaybeReturnMethod(){document.getElementById(''modalreturn2'').value = ModalDialog.value;ModalDialogRemoveWatch();}</script><script runat="server">sub page_load(s as object, e as eventArgs)if not isPostBack thenButton1.Attributes.Add("onclick", "YesNoCancel(''Yes, no, or cancelme'',''YesNoCancelReturnMethod()'');")end ifend sub</script><BODY ><table border=1 cellpadding=2 cellspacing=2 align=center width="60%"><tr><td align=left></td></tr><tr><td align=left></td></tr><tr><td align=left></td></tr><tr><td align=left><a href="javascript:YesNoCancel(''Yes, no, or cancelme'',''YesNoCancelReturnMethod()'');">Show Modal #1</a>1. <input type=text id=modalreturn1 name=modalreturn1value=''''></td></tr><tr><td align=left><a href="javascript:YesNoMaybe(''Yes, no, or maybeme'',''YesNoMaybeReturnMethod()'');">Show Modal #2</a>2. <input type=text id=modalreturn2 name=modalreturn2value=''''></td></tr><tr><td><BUTTON onclick="javascript:YesNoMaybe(''Yes, no, or maybeme'',''YesNoMaybeReturnMethod()'');" type="button">Open Child Window</BUTTON></td></tr></table><form runat="server"><asp:Button ID="Button1" text="submit" runat="server"/></form></BODY></HTML>************************************************** **********************************Thanks,Tom推荐答案文章< wd ******* *******@newssvr13.news.prodigy.com>, ts **** ******@ftsolutions.com 启发我们...In article <wd**************@newssvr13.news.prodigy.com>, ts**********@ftsolutions.com enlightened us with... 无论是否使用asp.net代码,页面都能正常工作(只要asp .net 按钮没有推。) The page works fine with or without the asp.net code (as long as the asp.net button is not pushed). 我的猜测,没有.net来测试这个...... 按下按钮后,页面将被提交给服务器,然后返回给客户端,该客户端将重新运行所有的javascript。 (在开头一直放一个警告(繁荣)或者其他东西,看看它是否有b $ b获得笑wn两次) 当这种情况发生时,子窗口的句柄会丢失,因为所有客户端 变量都会丢失之前的值。 这意味着您的子窗口正在调用不存在的代码,并且您的 父窗口没有引用原始子代。当孩子遇到 错误时(window.opener.ModalDialog.value - 没有对象引用任何 更多,所以没有值属性),全部脚本停止运作。 因此,它甚至不会自我关闭。 HTH - - - ~kaeli~ 澳大利亚局域网:......局域网下面。 http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpaceMy guess, not having .net to test this with...When the button is pushed, the page is submitted to the server and then comesback to the client, which runs all the javascript all over again.(put an alert("boom") or something all the way at the beginning and see if itgets shown twice)When that happens, the handle to the child window is lost, as all client-sidevariables lose their previous values.That means your child window is calling code that doesn''t exist and yourparent window has no reference to the original child. When the child hits theerror (window.opener.ModalDialog.value -- there is no object reference anymore, so there can be no value property), all script stops functioning.Hence, it won''t even self.close.HTH----~kaeli~Local Area Network in Australia:... the LAN down under. http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace嗯,首先,所有Javascript必须正确终止 并且在一行上。希望这只是它在 新闻组中发布的方式,因为如果我尝试运行它剪切和粘贴,我得到一堆 ''''未终止字符串文字''错误。我还是先修好所有那些 。 (另外,我发现Firefox javascript控制台比IE浏览器强大100倍 脚本对话框错误框)Well, for one thing all the Javascript has to be properly terminatedand on one line. Hopefully it is just the way it is posted in thenewsgroup, because if I try and run it cut and paste, I get a bunch of''''unterminated string literal'' errors. I am still fix all thosefirstly.(also, I find the Firefox javascript console 100x more powerful then IEscript dialog error box)我只是直截了当地提到了我上面提到的所有Javascript它和 对我来说很好用ASP.NET 1.1和Cassini(在Firefox 1.1和IE中 6)I just straighted out all the Javascript as I mentioned above and itworks fine for me using ASP.NET 1.1 and Cassini (in Firefox 1.1 and IE6) 这篇关于Javascript工作正常,直到按下asp.net按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-10 12:19