473,569 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button Click and JavaScript

Hi all

I have an ASP.NET Button Control. I woud like this button to make a Call to
JavaScript function on some condition. How would i do this

Thanks
Sekhar

Apr 27 '06 #1
5 1818
you need to add the javascript event ala

myButton.Attrib utes.Add("oncli ck", "doSomething(); ");

if the condition is server side, you can simply wrap the above line in your
if, otherwise put the condition in the doSomething() javascrit function.

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:19******** *************** ***********@mic rosoft.com...
Hi all

I have an ASP.NET Button Control. I woud like this button to make a Call
to
JavaScript function on some condition. How would i do this

Thanks
Sekhar

Apr 27 '06 #2
Add an attribute to your button (say btnTest)

btnTest.Attribu tes.Add("onClic k","your_javasc ript")

e.g.
btnTest.Attribu tes.Add("onClic k", "javascript:ale rt('Hello')";

or
btnTest.Attribu tes.Add("onClic k", "YourJavascript Function()")

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics. com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:19******** *************** ***********@mic rosoft.com...
Hi all

I have an ASP.NET Button Control. I woud like this button to make a Call
to
JavaScript function on some condition. How would i do this

Thanks
Sekhar

Apr 27 '06 #3
Hi
It doesnt work the way you suggested. Here is the scenario

I have a button btnTest and two text boxes UID and PWD
If the UID and PWD entered are valid, I would like to run the JavaScript Code

If I do it the way you suggested,
btnTest.Attribu tes.Add("onclic k","ClientEvent ()")
First the ClientEvent is fired then the Serverside code gets called which I
dont want to happen

I want the Client Side code to run only if the Condition is true on server
side

Thanks
Sekhar
"Swanand Mokashi" wrote:
Add an attribute to your button (say btnTest)

btnTest.Attribu tes.Add("onClic k","your_javasc ript")

e.g.
btnTest.Attribu tes.Add("onClic k", "javascript:ale rt('Hello')";

or
btnTest.Attribu tes.Add("onClic k", "YourJavascript Function()")

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics. com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:19******** *************** ***********@mic rosoft.com...
Hi all

I have an ASP.NET Button Control. I woud like this button to make a Call
to
JavaScript function on some condition. How would i do this

Thanks
Sekhar


Apr 27 '06 #4
In that case you can use the "RegisterClient ScriptBlock" --see
http://msdn.microsoft.com/library/de...BlockTopic.asp

You can add after you check the condition on the server.
--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics. com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:54******** *************** ***********@mic rosoft.com...
Hi
It doesnt work the way you suggested. Here is the scenario

I have a button btnTest and two text boxes UID and PWD
If the UID and PWD entered are valid, I would like to run the JavaScript
Code

If I do it the way you suggested,
btnTest.Attribu tes.Add("onclic k","ClientEvent ()")
First the ClientEvent is fired then the Serverside code gets called which
I
dont want to happen

I want the Client Side code to run only if the Condition is true on server
side

Thanks
Sekhar
"Swanand Mokashi" wrote:
Add an attribute to your button (say btnTest)

btnTest.Attribu tes.Add("onClic k","your_javasc ript")

e.g.
btnTest.Attribu tes.Add("onClic k", "javascript:ale rt('Hello')";

or
btnTest.Attribu tes.Add("onClic k", "YourJavascript Function()")

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics. com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:19******** *************** ***********@mic rosoft.com...
> Hi all
>
> I have an ASP.NET Button Control. I woud like this button to make a
> Call
> to
> JavaScript function on some condition. How would i do this
>
> Thanks
> Sekhar
>


Apr 27 '06 #5
If you want the server code to execute, return True from your javascript
function. Otherwise, return false;

Jeff
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:54******** *************** ***********@mic rosoft.com...
Hi
It doesnt work the way you suggested. Here is the scenario

I have a button btnTest and two text boxes UID and PWD
If the UID and PWD entered are valid, I would like to run the JavaScript
Code

If I do it the way you suggested,
btnTest.Attribu tes.Add("onclic k","ClientEvent ()")
First the ClientEvent is fired then the Serverside code gets called which
I
dont want to happen

I want the Client Side code to run only if the Condition is true on server
side

Thanks
Sekhar
"Swanand Mokashi" wrote:
Add an attribute to your button (say btnTest)

btnTest.Attribu tes.Add("onClic k","your_javasc ript")

e.g.
btnTest.Attribu tes.Add("onClic k", "javascript:ale rt('Hello')";

or
btnTest.Attribu tes.Add("onClic k", "YourJavascript Function()")

--
Swanand Mokashi
Microsoft Certified Solution Developer (.NET) - Early Achiever
Microsoft Certified Application Developer (.NET)

http://www.dotnetgenerics.com/
DotNetGenerics. com -- anything and everything about Microsoft .NET
technology ...

http://www.swanandmokashi.com/
http://www.swanandmokashi.com/HomePage/WebServices/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Sekhar" <Se****@discuss ions.microsoft. com> wrote in message
news:19******** *************** ***********@mic rosoft.com...
> Hi all
>
> I have an ASP.NET Button Control. I woud like this button to make a
> Call
> to
> JavaScript function on some condition. How would i do this
>
> Thanks
> Sekhar
>


Apr 27 '06 #6

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

Similar topics

3
4210
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons recieve focus when the page loads. Also, I would like that same button to fire its event when the user presses enter. Can anybody help with this? *** Sent via Developersdex...
14
7169
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by adding a java script for the button. But, useless.. Please help! Thank you
2
9024
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived object (both the HTML and control are built in the same .ascx file) The target button simply fires an event in the WebUserControl-derived object. So,...
4
5530
by: Carlo Marchesoni | last post by:
I have a button that opens a new Window (some kind of search-window), which is fired using JavaScript (btnSearch.Attributes=".....";) Now I need to run some code behind code BEFORE this JavaScript runs. I tried to define another Button with an EventHandler associated, and from this (after doing my code) fire 'btnSearch.click()'. But I can't make...
5
1920
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type image, the submit happens automatically to the server. Heres my problem: I have two event handlers for both these buttons as stated below: BUTTON...
11
13883
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to all users (btnSendAll). When user hits enter, I also simulate the effect of clicking button (btnSend). However, what I found btnSend doesn't fire...
3
8750
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called twice, once with postback true, and second time without postback. This only happens for this button. How can I sort out this issue, any clues what...
4
3498
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click...
1
6983
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the page has multiple button such login page with a search function somewhere around, then it's not respond properly. I have attached a brief example of...
19
4539
Frinavale
by: Frinavale | last post by:
I'm in the middle of implementing a custom Ajax enabled Server Control. At this point I need help finding the answer to an Ajax Framework question...here it goes: I have a Server Control that extends from a Panel and implements the IScriptControl interface: Public Class MyCustomControl Inherits Panel Implements IScriptControl ...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6287
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.