By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,225 Members | 2,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,225 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.