Solved

execute script in ASP.NET

Posted on 2008-10-21
21
708 Views
Last Modified: 2012-05-05
Hello,

I was wondering if there is a way to run a script based on a selection from a dropdownlist? The script installs the specified printer that would be selected fromt the dropdownlist.
0
Comment
Question by:asp_net2
  • 10
  • 9
  • 2
21 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22770487
what kind of script, vbscript? jscript?  
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22770517
vbscript
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22770649
I dont think so, there will be some serious security issue if you could do it.
the only kind of client script i know asp.net could run is javascript.
 
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 4

Author Comment

by:asp_net2
ID: 22770676
what about a DOS script or batch file?
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22770709
it<s like execution client code on a client browser. All code i know that does that use a securyty hole. Is the same kind of code that virus or worm could use to infect a computer.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22770786
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 22770791
Are you working on a intranet application? if yes then i can see the possiblity of doing it, if you trying to acheieve this for internet audience, then sorry it is actually a "Security Hole".
Your users need to add your website/Intranet site into the Trusted Zone within the Settings of Internet Explorer.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22770817
and i think that code run the bat file on the serverside (so it s useless to install the printer on the client)
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22772633
adilkhan,

Yes, basically we have around 10 different printers in my company and people are moving to different buildings ALL the time. So the network administrator and myself decided to try something different by letting the user select the printer at there location. The network administrator created the BAT file and now i have to get it to work in ASP.NET. However, i have never worked with something like this before and was hoping for a little help to get me started.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22772642
davrob60,

I'm not to worried about installing through the network other than client. At this point i'm just looking for some possibility either way.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22776037
ok, the link you sent is exeuted on the server, so it s useless.
You cant execut script on the client in asp.net. BUT there is way to execute script from VBscript (on the client side).
http://www.tek-tips.com/viewthread.cfm?qid=979664&page=1
what you need to do is populate your dropdownlist in Asp.net.  and then run that java script that will read the value from the dropdownlist.
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22776273
Wow, i was looking for an easier solution then this. I was looking for a way to just call the .bat file from a button click or even an SelectedIndexChanged Event from DropdownList.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22776376
well, you got all you need in the link.
asp.net control could have javascript event, like onclick for the button and OnChange for a dropdown.
then you could pass a control (your dropdown) as a javascript paramerer like this

onclick='<%# "myfunction(this, """ & mydropdown.clientid  """ )" %>'
to a function like this

function CheckKeyDown(buttonobject, dropdownID){

var dropdownObject = document.getElementById(dropdownID);
}
 
i hope it will help you
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22776385
the function "CheckKeyDown" should be replaced by "myfunction"
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22776444
Okay, could you let me know how the javascript code will look like if my DropdownList ID was called "DDL1" and my ASP.NET button was called "Button1".

Also how do i run the code in the link from Javascript?
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22776604
ok, i saw i m useless in that one.
i just saw the code i link you is... VBScript...
i never-ever use any vbscript on a page. my apology...
I would suggest you to delete this question and reask it, add more zones because the asp.net part is minor in that case and explain why you are doing this (the intranet and network administrator  part)
also, if you want, i could rewrite the code to run a javascript for yours controls.
 
 
 
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22776859
Javascript would be okay if you wouldn't mine.

My Dropdown ID is called "DDL1" and I will have 5 ListItems each will need to execute different .bat files to install different printers.
0
 
LVL 18

Expert Comment

by:David Robitaille
ID: 22776970
well i got to do some test before and it will take time...
are you willing to wait?
 
0
 
LVL 4

Author Comment

by:asp_net2
ID: 22776991
Yes, take your time this would really help me out. I'll keep the post open. Thanks in advance!
0
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 22778837
why dont you upload the script file as a ".zip" extension. and when user clicks on the url give them instruction using "onClick" event how to download the script (Right Click save Target As) and then have them execute from their machines.
0
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 22779118
thats not a "complete" solution but that answer the main question:
 "if there is a way to run a script based on a selection from a dropdownlist?"

 <form id="form1" runat="server">
            <asp:DropDownList ID="DDL1" runat="server" >
                <asp:ListItem Text="select printer" Value="" Selected="True" />
                <asp:ListItem Text="Printer 1" Value="c:\\test.bat" />
                <asp:ListItem Text="Printer 2" Value="c:\\test2.bat" />
            </asp:DropDownList>
           
    </form>
    <script type="text/vbscript">
     sub executebat(DropDownid) 
         document.write(DropDownid.value)
    end sub
   </script>
 
 
in the code beind:
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        DDL1.Attributes.Add("onchange", "executebat(" & DDL1.ClientID & ")")
 
    End Sub

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

816 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