473,414 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to call a client-side vbscript from server-side button

Hi all,

I need to pass a variable to the client-side vbscript and when the button is
pressed invoke the script (SomeSub()).
The problem is, that the "blablabla" appears only after second pressing of
the button.
Probably there is something with the postback, but I cannot figure it out.

My .aspx :

<asp:Button id="Button3" runat="server" Text="Butt"></asp:Button>
<script language="VBscript" type="text/vbscript">
Sub SomeSub()
Dim mystr
mystr = "<%= variable %>"
document.write("variable")
End Sub
</script>

On my .vb file I'v got:

Public variable As String = "blablabla"

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Button3.Attributes.Add("onclick", "SomeSub()")
End Sub

Please help me.

Nov 19 '05 #1
2 1906
Hi Alan

Yep, you're right. Your VBScript will always fire on the second click. This
is because your Attributes.Add occurs when the button is clicked, so you MUST
click the button in order for the VBs to be attached. You click it again,
it's attached, and it works!

To get that to work, get rid of the button handler (Private Sub
Button3_Click()) - unless you need it for something else of course, and add
the Attributes.Add to your page load...

Private Sub Page_Load()
Button3.Attributes.Add("onclick", "SomeSub()")
End Sub

Hope this helps,
Dan

"alan" wrote:
Hi all,

I need to pass a variable to the client-side vbscript and when the button is
pressed invoke the script (SomeSub()).
The problem is, that the "blablabla" appears only after second pressing of
the button.
Probably there is something with the postback, but I cannot figure it out.

My .aspx :

<asp:Button id="Button3" runat="server" Text="Butt"></asp:Button>
<script language="VBscript" type="text/vbscript">
Sub SomeSub()
Dim mystr
mystr = "<%= variable %>"
document.write("variable")
End Sub
</script>

On my .vb file I'v got:

Public variable As String = "blablabla"

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Button3.Attributes.Add("onclick", "SomeSub()")
End Sub

Please help me.

Nov 19 '05 #2
Hope this helps,
Dan


Yes, it works :)
Thank You Dan
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Prasad Patil | last post by:
Hi, I have a webform, The link on the webform should call the exe program installed on the client machine when the user click the link on the webform. It should run the exe installed on the...
0
by: Rashmi Dixit | last post by:
Hi, My application accesses DB2 over DB2 CLI and we use the calls SQLTables, SQLTablePrivileges, SQLColoumns to retrieve the schema information from the system catalog tables. When we call...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
11
by: Yahoo | last post by:
I have a programming issue where I need to know the whole history of the call stack to ensure it was never within a given method (specifically my own method). I am hooking into the XmlDocument...
5
by: Amaryllis | last post by:
I'm trying to call a CL which is located on our AS400 from a Windows application. I've tried to code it in different ways, but I seem to get the same error every time. Does anyone have any clue...
2
by: Dmitry Sazonov | last post by:
I'm novice here and I'm sorry for stupid question. We are trying to understand web services architecture, is it better than TIBCO.Randevouz and does webservices fit our needs. I understand, I...
5
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void...
0
by: gregarican | last post by:
Looking at the docs for xmlrpclib I didn't see a way to pass a client call with an expressed timeout value. What is the easiest way to accomplish this? Do I have to tap into the underlying HTTP...
3
by: harborboy76 | last post by:
I am calling the exact same stored procedure called myprocedure from 2 different boxes from the CLP, but I'm experiencing different behaviors between them. After I was unable to get any support...
5
by: tomas | last post by:
Hi. I wrote a code similar to this one, for a wrapper application that I needed: #include <iostream> using namespace std; class Client {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.