Solved

execute script in ASP.NET

Posted on 2008-10-21
21
711 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Industry Leaders: 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!

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 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