473,396 Members | 1,725 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,396 software developers and data experts.

How do you make a webform button run an onClick Javascript

Has anyone ever made a webform button run an onClick event that is a
Javascript in the HTML code and then after running the script make it go
into the code-behind? An HTML button will run the onClick event but will not
return to the code-behind. I need to get back to the code, which the webform
button will do but I can't make it execute the script.

Any help will be appreciated. Thanks.
Nov 22 '05 #1
2 4018
Theres an example below, just transfer the server side click event to code
behnd and it should work

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Cathy" <cm******@co.dutchess.ny.us> wrote in message
news:#H**************@tk2msftngp13.phx.gbl...
Has anyone ever made a webform button run an onClick event that is a
Javascript in the HTML code and then after running the script make it go
into the code-behind? An HTML button will run the onClick event but will not return to the code-behind. I need to get back to the code, which the webform button will do but I can't make it execute the script.

Any help will be appreciated. Thanks.


<html>
<head>
<script language="VB" runat="server">

Sub Page_Load( sender as Object,e as EventArgs)
'Form the script that is to be registered at client side.
Dim scriptString as String = "<script language=JavaScript> function
onClientClick() {"

ScriptString += "var retVal = window.confirm('Click OK to continue.
Click Cancel to stop.');"
ScriptString += "window.alert(retVal);"
ScriptString += "if (retVal){"
ScriptString += "window.alert('MVP Code is doing the Postback!');"
ScriptString += "return true;"
ScriptString += "}"
ScriptString += "else"
ScriptString += "{"
ScriptString += "window.alert('MVP Code is NOT Doing the
Postback!');"
ScriptString += "return false;"
ScriptString += "}"
ScriptString += "}<"
scriptString += "/"
scriptString += "script>"

If(Not IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", scriptString)
End If
End Sub
Sub button_onClick( sender as Object,e as EventArgs)
Response.Write("Postback as requested!!!" + DateTime.Now())
End Sub
</script>
</head>
<body topmargin="20" leftmargin="10">
<form id="myForm" runat="server">
<input type="button" value="OK" onserverclick="button_onClick"
onclick="if(!onClientClick()){return false;}"
runat="server">

</form>
</body>
</html>
Nov 22 '05 #2
Cathy,

Use VBNet webform project, and than
drag a webform button and a textbox on your page and paste in this in the
code behind

\\\
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Me.TextBox1.Text = "Click the button"
Me.Button1.Text = "Send Mail"
Me.Button1.Attributes("onClick") = _
"window.location='mailto:no*@non.com?subject=C or demo&body=I
hope this helps?';"
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.TextBox1.Text = "I was on the ServerSide"
Me.Button1.visible = False
End Sub
///

I hope this helps?

Cor
Nov 22 '05 #3

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

Similar topics

2
by: Cathy | last post by:
Has anyone ever made a webform button run an onClick event that is a Javascript in the HTML code and then after running the script make it go into the code-behind? An HTML button will run the...
5
by: TrvlOrm | last post by:
Can any one please help me...I am new to JavaScript and I have been struggling with this code for days now and can't figure it out. I would like to get the Buttons to correspond with the action...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
2
by: Srinivas | last post by:
Hi, I have a webform with some dropdown menus, textboxes required and custom validators. I added a click event handler for the button in which there is code for processing. This processing takes...
2
by: Sedef | last post by:
Hi, i'm trying to create a custom Button user control which will be derived from System.Web.UI.WebControls.Button. the normal server side Button class creates some client side javascript code for...
3
by: Arne | last post by:
How do I make a web form control react to a client side event in the browser THe onclick event to server based. I am looking for onclick event on the client I need something like this from a...
1
by: ruca | last post by:
Hi I have an image button (called ibtnBack) that I want when clicked he go to the previous page, just like it happens when you press back button of Internet Explorer. For that I already used...
2
by: Mike | last post by:
I am trying to call one webform from the click event of a button on another webform. In VB6 windows applications, this is a simple Form.Show, but I can't figure out the syntax to call Webforms....
2
by: almurph | last post by:
Hi everyone, I have an APS.NET (v1.1) type button on a webform page. What I want it to do is when the user clicks it, it then calls another webform page that appears in a pop-up window. Now I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.