Solved

open  dialogbox in ASP.NET

Posted on 2006-07-10
16
1,738 Views
Last Modified: 2008-02-26
I am using this code below so that i can open a dialog box and select a folder from a drive, and make the folder name and path show up on the text box in the web form, but it doesn't open the dialog box.

Any idea?

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Button6.Attributes.Add("OnClick", "ShowDialog();")
    End Sub

thanks
0
Comment
Question by:jskfan
  • 6
  • 5
  • 3
  • +2
16 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
Comment Utility
Hello jskfan,

>   Me.Button6.Attributes.Add("OnClick", "ShowDialog();")
move this into Form_PreRender event

HTH

I
0
 

Author Comment

by:jskfan
Comment Utility
<<<<<<<<<Me.Button6.Attributes.Add("OnClick", "ShowDialog();")
move this into Form_PreRender event>>>>>>>>>>>>.



it still doesn't do anything

0
 
LVL 39

Expert Comment

by:Pratima Pharande
Comment Utility
try this in page_load.....................

May i see the code in ShowDialog() ?
0
 
LVL 27

Assisted Solution

by:Sammy
Sammy earned 100 total points
Comment Utility
can you post the  ShowDialog() client code?
If I were to add this code in the page_load event of the webform Me.Button6.Attributes.Add("OnClick", "ShowDialog();")  and ShowDialog is a valid function, whatever script in the function will be executed

example

<script type="text/javascript">
function ShowAlert()
{
alert('Hello');
}
</script>

and in the page_load you add Me.Button6.Attributes.Add("OnClick", "ShowAlert();") the script will run fine.

one more thing you said >>i can open a dialog box and select a folder from a drive, and make the folder name and path show up on the text box in the web form
are you trying to upload a file to the server? If yes then you can use <input id="uplTheFile" type=file runat="server"> in asp.net 1.1 or <asp:FileUpload ID="browse" runat="server" /> in asp.net 2.0

HTH
0
 
LVL 22

Assisted Solution

by:Ivo Stoykov
Ivo Stoykov earned 100 total points
Comment Utility
Hi jskfan,

add also on page_load function

        Dim scriptString as String = "<script language=JavaScript> function ShowDialog() {"
        scriptString += "alert('Hi there'); }<"
        scriptString += "/"
        scriptString += "script>"
     
            If(Not IsClientScriptBlockRegistered("clientScript"))
        RegisterClientScriptBlock("dlg", scriptString)
        End If



regards

I
0
 

Author Comment

by:jskfan
Comment Utility
the goal is to open a dialog  box and select a folder name in the network drive
0
 
LVL 22

Expert Comment

by:Ivo Stoykov
Comment Utility
Hi jskfan,

you cannot open a network drive with a browser unless it is mapped. This is a security issue.

regards

I
0
 
LVL 22

Expert Comment

by:Ivo Stoykov
Comment Utility
Hi jskfan,

Here is a sample of open folder dialog but you have to set permissions accordingly.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function t()
{
  var WINDOW_HANDLE = 0;
  var OPTIONS = 0;

  var objShell = new ActiveXObject("Shell.Application");
  var objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "Select a folder:", OPTIONS, "C:\\");

  if(objFolder== null)  {    Wscript.Quit() ; }

  var objFolderItem = objFolder;
  var objPath = objFolderItem.Path;

  document.write(objPath);
}  // end function

//-->
</SCRIPT>
</HEAD>

<BODY onclick="t();">
Click me
</BODY>
</HTML>


regards

I
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:jskfan
Comment Utility
ivostoykov ,

where do you want me to paste this HTML code above?
I need a click button that browse through the drive folders
0
 
LVL 22

Expert Comment

by:Ivo Stoykov
Comment Utility
Hi jskfan,

sorry for the delay but i was out for a wahile...

1. Add script as a standard script block into the header
2. attach finction to desired object, i.e.
Me.Button6.Attributes.Add("OnClick", "t();")

regards

I
0
 
LVL 7

Accepted Solution

by:
skvikram earned 300 total points
Comment Utility
<%@ Import Namespace="System.IO" %>
<Script runat="Server">
Sub Button3_Click(sender As Object, e As EventArgs)
Dim inFile as string
infile=inpFileUp.PostedFile.FileName
txtbox.Text = infile
End Sub
</Script>
<html><head></Head><body>
<form runat="server">
    <input id="inpFileUp"  tabIndex="7" size="20" Type="File" Runat="server" />
    <asp:TextBox id="txtBox" runat="server" />
    <asp:Button id="Button3" onclick="Button3_Click" Text="Save" runat="server"/>

</form>
</body></html>
0
 

Author Comment

by:jskfan
Comment Utility
Sorry, I am using ASP.NET and could not get your code to work
0
 
LVL 7

Expert Comment

by:skvikram
Comment Utility
Hi jskfan,
The code is indeed for asp.net

The button3_click subroutine executes and displays the cotents of open file dialog in a textbox .

I am using this code in an ecommerce ASP.NET web application. And it's working.
0
 

Author Comment

by:jskfan
Comment Utility
skvikram ,

that was excellent!!!

1-I didn't know that you can  put sub procedure in the HTML page, I did and it run just good.

2-Can the open dialog box pickup a folder instead of a file? if it is not incovenient for you can you show me how to do it?

Thanks a lot!!!!
0
 

Author Comment

by:jskfan
Comment Utility
In other words, can you please take a little bit more of pain to explain your code?
 thanks
0
 
LVL 7

Assisted Solution

by:skvikram
skvikram earned 300 total points
Comment Utility
It is simple the button3_click subroutine takes the filename in infile variable and puts this in text box.

Dim inFile as string
infile=inpFileUp.PostedFile.FileName
Dim infolder as string
infolder=Path.GetDiretoryName(infile)
txtbox.Text = infolder


0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now