Solved

open  dialogbox in ASP.NET

Posted on 2006-07-10
16
1,761 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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 …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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