0

I have an asp.net 4.5 app using this as the base. I'm trying to find the bug in my code as it doesn't return the value from my modalpopup back to my 'TextBox1' on my default page.

I have a default.aspx page with the following:

<asp:TextBox ID="TextBox1" runat="server" />
<asp:Button ID="btnSelectFolder" runat="server" Text="Select Folder" OnClientClick="showDirectory();"/>

The default.aspx references my Site.Master page with the following JavaScript

<html lang="en">
<head runat="server">
    <meta charset="utf-8" />
    <title><%: Page.Title %> - My ASP.NET Application</title>
    <asp:PlaceHolder runat="server">     
          <%: Scripts.Render("~/bundles/modernizr") %>
    </asp:PlaceHolder>  
    <webopt:BundleReference runat="server" Path="~/Content/css" /> 
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    <asp:ContentPlaceHolder runat="server" ID="HeadContent" />
    <script type="text/javascript">
        function showDirectory() {
            document.all.TextBox1.value = window.showModalDialog("browseDirectory.aspx",
                        'jain',
                        "dialogHeight: 560px; dialogWidth:360px; edge: Raised; center: Yes; help: Yes; resizable: Yes; status: No;");
            return false;
        }
    </script>
</head>

On my modalPopup (BrowseDirectory.aspx) I have the following JavaScript (SelectAndClose() function) that should return the contents of the _browseTextBox to my original Default.aspx page , but it returns a null error ( I included the entire header section):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BrowseDirectory.aspx.cs" Inherits="DirectoryBrowsin.BrowseDirectory" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Borwse Directory</title>
    <style>
            .errorMsg{FONT-SIZE: 8.25pt; COLOR: red; FONT-FAMILY: Verdana, Arial; TEXT-DECORATION: none }
            .hilite { BACKGROUND-COLOR: #dfe5ff }
            .nohilite { BACKGROUND-COLOR: #ffffff }
            .text { FONT-SIZE: 8.25pt; COLOR: black; FONT-FAMILY: Verdana, Arial; TEXT-DECORATION: none }
            .tableOutlineWt { BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #666666 1px solid; MARGIN-TOP: 0px; OVERFLOW: auto; BORDER-LEFT: #333333 1px solid; PADDING-TOP: 0px; BORDER-BOTTOM: #cccccc 1px solid }
        </style>
    <script type="text/javascript">
    function SelectAndClose()
    {
        txtValue = document.getElementById('_browseTextBox');
        window.returnValue = txtValue.value;
        window.close();
        return false;
    }




    </script>
</head>
Danimal111
  • 1,976
  • 25
  • 31
  • what is the purpose of return false?? you can remove that and try! function showDirectory() { .......//// return false; } – user1769790 Mar 20 '14 at 00:12
  • Doesn't help. And it is pulling the value in the _browseTextBox, it just doesn't make it back to the original page. – Danimal111 Mar 20 '14 at 00:19

1 Answers1

0

window.shoModalDialog is not implemented the same in all browsers. It first appeared in one of the earlier Internet Explorer browsers. Take a look at this SO answer on this topic: https://stackoverflow.com/a/10234548/2488939

Community
  • 1
  • 1
The Mahahaj
  • 696
  • 6
  • 8
  • Seems this is a awful way to go (ModalPopup) is there a better way to do this? PS - I can't get that bug fix to work either!!! – Danimal111 Mar 20 '14 at 00:45
  • @DanB To launch a new window you can use window.open('...'), but you won't get the dialog to be modal (It's only modal in Internet explorer). So if you want to go that route you can look at this SO thread: http://stackoverflow.com/a/16423057/2488939 – The Mahahaj Mar 20 '14 at 01:04