469,589 Members | 2,157 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,589 developers. It's quick & easy.

Why can't I execute Javascript in a modal dialog window?

jm
I have a parent window:
<script language="javascript">
function doSearch() {
result=showModalDialog("searchmni.aspx?lastname=sm ith");
alert(result);
}

</script>
<input id="btnOpenSearch" onclick="doSearch();" type="button"
value="search" runat="server" text="Button" />
<input type=textbox id="txtResponse" >

In my child window, the popup populates and then has a bound
hyperlinkcolumn. For testing sakes, I just put this for the
hyperlinkcolumns argument:

<asp:HyperLinkColumn DataNavigateUrlField="mniMiddleName"
DataNavigateUrlFormatString="javascript:testlink() ;"
DataTextField="mniMiddleName" HeaderText="Middle Name"
DataTextFormatString="{0}"></asp:HyperLinkColumn>

the javascript is simple:

function testlink(){
window.returnValue="test";
window.close();
}

What I found was that if I click the hyperlinkcolumn in the modal
dialog, the javascript opens another window. It does not simply
execute the javascript. If I run the modal dialog as a normal page, I
can get code to execute (of course it does nothing as it is not a
dialog at that point) - no errors. It is simply because it is inside
the modal. Any ideas how to make this code execute?

I have tried:

DataNavigateUrlFormatString="javascript: var x=testlink();"
DataNavigateUrlFormatString="javascript: var x=if(testlink();)"

all of them open another window with the call to the javascript in the
address bar.

What am I doing wrong? Thank you.
Nov 18 '05 #1
2 4093
it's due to the properties of the ModalDialog window.... it's not meant to
do that type of stuff from what I've been told. Goto a window.open instead
of a window.showmodaldialog
--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com
"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have a parent window:
<script language="javascript">
function doSearch() {
result=showModalDialog("searchmni.aspx?lastname=sm ith");
alert(result);
}

</script>
<input id="btnOpenSearch" onclick="doSearch();" type="button"
value="search" runat="server" text="Button" />
<input type=textbox id="txtResponse" >

In my child window, the popup populates and then has a bound
hyperlinkcolumn. For testing sakes, I just put this for the
hyperlinkcolumns argument:

<asp:HyperLinkColumn DataNavigateUrlField="mniMiddleName"
DataNavigateUrlFormatString="javascript:testlink() ;"
DataTextField="mniMiddleName" HeaderText="Middle Name"
DataTextFormatString="{0}"></asp:HyperLinkColumn>

the javascript is simple:

function testlink(){
window.returnValue="test";
window.close();
}

What I found was that if I click the hyperlinkcolumn in the modal
dialog, the javascript opens another window. It does not simply
execute the javascript. If I run the modal dialog as a normal page, I
can get code to execute (of course it does nothing as it is not a
dialog at that point) - no errors. It is simply because it is inside
the modal. Any ideas how to make this code execute?

I have tried:

DataNavigateUrlFormatString="javascript: var x=testlink();"
DataNavigateUrlFormatString="javascript: var x=if(testlink();)"

all of them open another window with the call to the javascript in the
address bar.

What am I doing wrong? Thank you.

Nov 18 '05 #2
Set smartNavigatoin=true on the dialog page. Then the page should refresh
into itself.

Cathie

"jm" <jo*************@yahoo.com> wrote in message
news:c6**************************@posting.google.c om...
I have a parent window:
<script language="javascript">
function doSearch() {
result=showModalDialog("searchmni.aspx?lastname=sm ith");
alert(result);
}

</script>
<input id="btnOpenSearch" onclick="doSearch();" type="button"
value="search" runat="server" text="Button" />
<input type=textbox id="txtResponse" >

In my child window, the popup populates and then has a bound
hyperlinkcolumn. For testing sakes, I just put this for the
hyperlinkcolumns argument:

<asp:HyperLinkColumn DataNavigateUrlField="mniMiddleName"
DataNavigateUrlFormatString="javascript:testlink() ;"
DataTextField="mniMiddleName" HeaderText="Middle Name"
DataTextFormatString="{0}"></asp:HyperLinkColumn>

the javascript is simple:

function testlink(){
window.returnValue="test";
window.close();
}

What I found was that if I click the hyperlinkcolumn in the modal
dialog, the javascript opens another window. It does not simply
execute the javascript. If I run the modal dialog as a normal page, I
can get code to execute (of course it does nothing as it is not a
dialog at that point) - no errors. It is simply because it is inside
the modal. Any ideas how to make this code execute?

I have tried:

DataNavigateUrlFormatString="javascript: var x=testlink();"
DataNavigateUrlFormatString="javascript: var x=if(testlink();)"

all of them open another window with the call to the javascript in the
address bar.

What am I doing wrong? Thank you.

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bjoern Obermeyer | last post: by
2 posts views Thread by John | last post: by
4 posts views Thread by Brian Henry | last post: by
10 posts views Thread by Guadala Harry | last post: by
3 posts views Thread by =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.