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

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 1811
you need to add the javascript event ala

myButton.Attributes.Add("onclick", "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****@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.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.Attributes.Add("onClick","your_javascript" )

e.g.
btnTest.Attributes.Add("onClick", "javascript:alert('Hello')";

or
btnTest.Attributes.Add("onClick", "YourJavascriptFunction()")

--
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****@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.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.Attributes.Add("onclick","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.Attributes.Add("onClick","your_javascript" )

e.g.
btnTest.Attributes.Add("onClick", "javascript:alert('Hello')";

or
btnTest.Attributes.Add("onClick", "YourJavascriptFunction()")

--
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****@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.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 "RegisterClientScriptBlock" --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****@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.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.Attributes.Add("onclick","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.Attributes.Add("onClick","your_javascript" )

e.g.
btnTest.Attributes.Add("onClick", "javascript:alert('Hello')";

or
btnTest.Attributes.Add("onClick", "YourJavascriptFunction()")

--
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****@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.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****@discussions.microsoft.com> wrote in message
news:54**********************************@microsof t.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.Attributes.Add("onclick","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.Attributes.Add("onClick","your_javascript" )

e.g.
btnTest.Attributes.Add("onClick", "javascript:alert('Hello')";

or
btnTest.Attributes.Add("onClick", "YourJavascriptFunction()")

--
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****@discussions.microsoft.com> wrote in message
news:19**********************************@microsof t.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
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...
14
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...
2
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...
4
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...
5
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...
11
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...
3
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...
4
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...
1
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...
19
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...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...

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.