Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

execute script in ASP.NET

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
asp_net2
Asked:
asp_net2
  • 10
  • 9
  • 2
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
what kind of script, vbscript? jscript?  
0
 
asp_net2Author Commented:
vbscript
0
 
David RobitailleAnalyst ProgrammerCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
asp_net2Author Commented:
what about a DOS script or batch file?
0
 
David RobitailleAnalyst ProgrammerCommented:
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
 
asp_net2Author Commented:
0
 
Saqib KhanSenior DeveloperCommented:
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
 
David RobitailleAnalyst ProgrammerCommented:
and i think that code run the bat file on the serverside (so it s useless to install the printer on the client)
0
 
asp_net2Author Commented:
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
 
asp_net2Author Commented:
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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
asp_net2Author Commented:
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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
David RobitailleAnalyst ProgrammerCommented:
the function "CheckKeyDown" should be replaced by "myfunction"
0
 
asp_net2Author Commented:
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
 
David RobitailleAnalyst ProgrammerCommented:
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
 
asp_net2Author Commented:
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
 
David RobitailleAnalyst ProgrammerCommented:
well i got to do some test before and it will take time...
are you willing to wait?
 
0
 
asp_net2Author Commented:
Yes, take your time this would really help me out. I'll keep the post open. Thanks in advance!
0
 
Saqib KhanSenior DeveloperCommented:
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
 
David RobitailleAnalyst ProgrammerCommented:
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

Hire Technology Freelancers with Gigs

Work with 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.

  • 10
  • 9
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now