Solved

execute script in ASP.NET

Posted on 2008-10-21
21
707 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
 
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:adilkhan
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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:adilkhan
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 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

17 Experts available now in Live!

Get 1:1 Help Now