Solved

execute script in ASP.NET

Posted on 2008-10-21
21
706 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
Comment Utility
what kind of script, vbscript? jscript?  
0
 
LVL 4

Author Comment

by:asp_net2
Comment Utility
vbscript
0
 
LVL 18

Expert Comment

by:David Robitaille
Comment Utility
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
Comment Utility
what about a DOS script or batch file?
0
 
LVL 18

Expert Comment

by:David Robitaille
Comment Utility
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
Comment Utility
0
 
LVL 23

Expert Comment

by:adilkhan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 18

Expert Comment

by:David Robitaille
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
the function "CheckKeyDown" should be replaced by "myfunction"
0
 
LVL 4

Author Comment

by:asp_net2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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