473,414 Members | 1,674 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.

Associate Command Button to Javascript Code

How do I associate a server side command button to a
Javascript function that is in the Web Form HTML Code?

Thanks
Nov 18 '05 #1
2 3011
You have to use RegisterClientScriptBlock to write a javascript funciton to
browser... to associate it... just use say onclick='function_name();' add
that to ur control...
Here's some code from my earlier post:

on aspx page
<td colspan="3">
<asp:LinkButton id="lnkUpdate"
runat="server">Update</asp:LinkButton>&nbsp;&nbsp;
<asp:HyperLink id="lnkCancel" onclick='CancelMe();' runat="server"
NavigateUrl="#">Cancel</asp:HyperLink>
</td>

in code behind .cs file within Page

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// Form the script that is to be registered at client side.
String scriptString = "<script language=JavaScript> function CancelMe()
{";
scriptString += "window.history.back(); }</script>";

if(!this.IsClientScriptBlockRegistered("clientScri ptCancel"))
this.RegisterClientScriptBlock("clientScriptCancel ", scriptString);

if(!Page.IsPostBack)
...............

"Angel" <as****@hotmail.com> wrote in message
news:00****************************@phx.gbl...
How do I associate a server side command button to a
Javascript function that is in the Web Form HTML Code?

Thanks

Nov 18 '05 #2
Hi.

Use Attributes collection of the Button web control.
Ex:

public Button btn;

public void SomeEvent(someParameters)
{
btn.Attributes["onClick"] = "javascript: alert('Event
happened');";
}

Check the syntax (I'm avay from VS right now :))

Regards.

-----Original Message-----
How do I associate a server side command button to a
Javascript function that is in the Web Form HTML Code?

Thanks
.

Nov 18 '05 #3

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

Similar topics

1
by: knutsample | last post by:
Hello! I'm trying to associate a file extension to my wxPython script so that all I have to do is double click on the file and my python script will load up with the path of that file. For...
6
by: Ashok | last post by:
hi, i want to know how to make a specific type of file open in an application i developed in python when the user clicks on the file.(in windows) for eg. a .txt file when clicked opens in notepad,...
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
0
by: Dailan | last post by:
Hi, I create a tree view. Each node has link button associate with it, which includes add, edit, delete buttons. The way I did is for users who have very low capablity of using computer. Now I...
8
by: moondaddy | last post by:
Is there a way to make the browser move back to the previous page via code behind on the server? The effect would be the same as the user clicking on the browser's back button. Thanks. --...
1
by: siaj | last post by:
Helo All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: Steve | last post by:
asp.net 2.0 I have a simple button control which implements some page behind code when it is clicked. I am looking for a simple javascript command which will in effect cause a click on the...
2
by: supermonkey | last post by:
As we all known, a menuItem often has a corresponding toolbar button in a windows form program. I want to associate a menuItem with corresponding toobarbutton which has the same action with it....
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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.