VB6 usercontrol Raise Event, how to catch the event in VBSCRIPT? - events

I am trying to catch an event in the VBSCRIPT of an html page but I can't make it work. I must have missed a step.
This is the code of my usercontrol (VB6):
Public Event sendText(ByVal Text As String)
Private Sub Command1_Click()
RaiseEvent sendText(Text1.Text)
End Sub
And this is the code of my web page (HTML):
<form>
<OBJECT name="ActiveX" id="ActiveX" classid="clsid:..."></OBJECT>
<script language="VBScript">
Sub ActiveX_sendText(Text)
Msgbox("aaa" & Text)
End Sub
</script>
</form>
The Event is raised in the user control when clicking the Command1 button, but I never get into the VBSCRIPT function.
I am using IE8/IE8 Standard.
Any clue?

It was a problem in the configuration of security rules in Internet Explorer. After enabling unsigned ActiveX, the issue was solved.

Related

Display loading gif before the page appears

First of all I'm a complete beginner when it comes to VBscripts.
I have only one asp file written in VB that starts a batch file.
The thing is that I want something that indicates that the page is loading like a gif. The batch takes almost 10 minutes to run and what I get is a blank page until it is finnished.
This is my entire code
<%# Language = VBScript %>
<HTML>
<script runat="server" language=VBScript>
' The batch file is running here
Dim myExecutor
Dim commandline
commandline = "cmd.exe /c C:\test.bat "
Set myExecutor = Server.CreateObject("WScript.Shell")
myExecutor.Run commandline,0,true
Set myExecutor = Nothing
Response.Write "The batch run is finnished <p> "
</script>
<body>
The batch is loading. <!--renders after batch is finnished :/ -->
</body>
</HTML>
I tried to run an onclick event <asp:Button Text="Click here" OnClick="run_batch" runat="server"/> but gives me a 500 page error when i use the sender As Object, e As EventArgs as parameters probably because I dont have the classes and only runns everything in one asp file.
Thanks.
The problem is that your code will execute as soon as the page loads. Define what you want to do as a Sub and call that in the onload event handler. The event will fire once everything on the page is loaded.
I tested the following in an hta and it works. Not sure how well it converts to asp.
<HTML>
<script language=VBScript>
sub DoStuff()
document.Write "<p>Doing stuff </p>"
CreateObject("WScript.Shell").Run "ping localhost",0,true
document.Write "<p>The batch run is finished <p> "
end sub
</script>
<body onload="DoStuff()">
</body>
</HTML>
Alternatively for a button approach just use
<button onclick="DoStuff()"> Do Stuff </button>

Load Subroutines From External Script File

I want to put my subroutines in an external file. When I press the help button it pops up errors. Even at startup it shows errors. If I put the contents of scripts.vbs within the HTA they work fine.
Here is the code:
Contents of scripts.vbs file:
Sub Window_Onload
Msgbox "welcome"
end sub
Sub Help
MsgBox "This is an example of progressbar in HTA written by Fredledingue.",,MyTitle
End Sub
Contents of HTA file:
<script type="text/vbscript" src="scripts.vbs">
</script>
<body bgcolor="GreenYellow">
<input id="BtnHelp" type="button" value="Help" onclick="Help">
Importing the script file like that should work, as long as the HTA and VBScript files are located in the same folder. You need to make sure that the <script> tag is closed though:
<script type="text/vbscript" src="scripts.vbs"></script>
If you still get errors you need to show them (full error message, including error number and the line raising the error).
With that said, I'd recommend against externalizing code from HTAs, because it reduces mobility. A self-contained HTA can easily be copied to wherever you like. The need to keep several files together has a negative impact on that.

prevent user closing a HTA

Using vbscript in a HTA
Aim: To prevent a user closing the HTA (except by my custom button or by using windows taskmanager)
As i understand from various webpages; You cannot prevent the HTA from closing when the close button is clicked in the HTA SYSMENU. Therefore my solution is to prevent the user from clicking close in the first place.
First up is to disable the system menu:
<HTA:APPLICATION SYSMENU="no" />
nb. I will replace the system menu with a custom one - any links to a good guide for this would be appreciated.
Next prevent keyboard shortcuts alt+f4, f5, or escape as follows:
Function Document_onKeyDown()
Dim alt
alt = window.event.altKey
Select Case window.event.keyCode
Case 27,116
window.event.keyCode = 0
window.event.cancelBubble = true
Document_onKeyDown = False
Case 115
If alt Then
window.event.keyCode = 0
window.event.cancelBubble = true
Document_onKeyDown = False
End If
Case Else
Document_onKeyDown = True
End Select
End Function
Finally I want to prevent the user using the windows taskbar context menu for my HTA app.
How can I prevent the user from seeing a context menu by right clicking my HTA?
nb. The HTA window cannot be full screen
Don't mess with a user's options to close your application. It's not up to you to decide how a user should work. Instead add a cleanup procedure where you do all the "on close" tasks and then call it on the beforeunload event:
<html>
<head>
<title>Sample</title>
<HTA:APPLICATION
ID="oHTA"
APPLICATIONNAME="sample"
/>
<script language="VBScript">
Sub cleanup
'clean up stuff here
End Sub
</script>
</head>
<body onbeforeunload="cleanup">
...
</body>
</html>
With regards:
How can I prevent the user from seeing a context menu by right clicking my HTA?
<HTA:APPLICATION contextMenu="no">
<HTA:APPLICATION showintaskbar="no">

Request.form doesn't return a value with Visual Studio 2013 in code behind

I think I'm getting blind....! What's wrong with the following code?
With Visual Studio 2013 "searchBox" doesn't return a value but with VS 2008 it works well.
CODE BEHIND
Partial Class _Default
Inherits Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(Request.Form("searchBox"))
End Sub
End Class
HTML PAGE
<%# Page validateRequest="false" Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:TextBox ID="SearchBox" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" />
</asp:Content>
It can't works with VS2008 either. As it is a server control, the actual client id of the control won't be searchbox but a concatenation of all parents ids of the control. Something like ctl00_somePanel_someContainer_SearchBox.
Request.Form will contain raw html form control's values, including the value generated by the client side version of the SearchBox, with its actual generated id.
To solve your issue, you can:
read the SearchBox.Text property instead of reading the Form object (probably the best option)
replace the server control by a pure client one (<input type='textbox' id='SearchBox'/>
fix the control ID using CliendIDMode, but I believe this is a poor option
The easiest would be when you want to use Request.Form("searchBox") is to set it as follows:
<asp:TextBox ID="SearchBox" clientmode="Static" runat="server"></asp:TextBox>
This forces the object to be created with the name "SearchBox" that you set it too, not "ctl00_somePanel_someContainer_SearchBox" that is a name that only it knows how to interpret.
It is not the best way to access the object, but this will get you going the way you are doing it.

Prototype framework / call from button

I thought this was pretty straight forward but I don't get the same results as the tutorials I read. I have a button on an html page that calls a function in script tags. I also have a reference to the prototype.js file which I haven't even begun to implement yet. If I leave that reference in the page, my function call does not work from the button's onclick event. Below is what is called from the button onclick event.
callIt = function(){
alert('It worked!');
}
</script>
A couple of things: first, make sure your HTML is valid. Run it through the validator at http://validator.wc.org.
Next, once you're sure that your page is valid, add the prototype.js library as the first script reference on the page:
<script type="text/javascript" src="prototype.js"></script>
Notice that I didn't close it like this <script ... /> Script blocks need to have an explicit closing tag (at least in XHTML 1.0 Transitional)
Now, to answer your question, I'm really not sure what you're asking, but if you wanted to attach the callIt method to the onclick handler of your button using Prototype, then do this:
Event.observe(window, 'load', function() {
Event.observe('button_id', 'click', callIt);
});
Put this in script tags in the element of the page, below the prototype script reference. This will execute when the DOM is loaded & the button exists on the page.
Hope this helps.
That worked. I'm just puzzled why none of the examples I have been working from have done this.
Thanks!

Resources