Solved

open  dialogbox in ASP.NET

Posted on 2006-07-10
16
1,769 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
ID: 17071113
Hello jskfan,

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

HTH

I
0
 

Author Comment

by:jskfan
ID: 17071184
<<<<<<<<<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
ID: 17071269
try this in page_load.....................

May i see the code in ShowDialog() ?
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 27

Assisted Solution

by:Sammy
Sammy earned 100 total points
ID: 17071303
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
ID: 17071450
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
ID: 17075296
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
ID: 17088209
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
ID: 17088239
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
 

Author Comment

by:jskfan
ID: 17109325
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
ID: 17119890
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
ID: 17130361
<%@ 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
ID: 17161550
Sorry, I am using ASP.NET and could not get your code to work
0
 
LVL 7

Expert Comment

by:skvikram
ID: 17162220
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
ID: 17162861
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
ID: 17162885
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
ID: 17163023
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.net Have sliders change in order 2 30
Creating a route in asp.net webforms 2 32
Error handling in asp.net site 5 34
No Data for DropDown List 2 28
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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