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

J

jm

I have a parent window:


<script language="javascript">
function doSearch() {
result=showModalDialog("searchmni.aspx?lastname=smith");
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.
 
C

Curt_C [MVP]

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
 
C

Cathie

Set smartNavigatoin=true on the dialog page. Then the page should refresh
into itself.

Cathie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top