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

precedence between OnClientClick and OnClick?

Hi,

I'm a little confused about the precedence of actions between OnClientClick
and OnClick. In this example, what will be executed first and why?

Thanks
Phil

in code-behind:
---------------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Hiddenfield1.value="end text"
....
end sub

in aspx file:
----------
<asp:HiddenField ID="hd1" runat="server" value="beginning
text"></asp:HiddenField>
<asp:Button ID="Button1" OnClientClick="test()" runat="server"/>

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("hd1").value
alert(x)
}
</script>
Mar 8 '07 #1
3 5667
"Phil" <ss*******@fff.dfwrote in message
news:Ol**************@TK2MSFTNGP05.phx.gbl...
I'm a little confused about the precedence of actions between
OnClientClick and OnClick. In this example, what will be executed first
and why?
OnClientClick gets executed first so that the postback can be cancelled if
required...

<script type="text/javascript">
function validateForm()
{
if (something fails)
{
return false;
}
}
</script>

<asp:Button ID="Button1" runat="server" OnClientClick="return
validateForm();" OnClick="Button1_Click" Text="Click me" />
Mar 8 '07 #2
OnClientClick always goes first since it happens on client side, when you
view the page in your browser. OnClick happens on the server where the page
arrives after a postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Phil" <ss*******@fff.dfwrote in message
news:Ol**************@TK2MSFTNGP05.phx.gbl...
Hi,

I'm a little confused about the precedence of actions between
OnClientClick
and OnClick. In this example, what will be executed first and why?

Thanks
Phil

in code-behind:
---------------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Hiddenfield1.value="end text"
....
end sub

in aspx file:
----------
<asp:HiddenField ID="hd1" runat="server" value="beginning
text"></asp:HiddenField>
<asp:Button ID="Button1" OnClientClick="test()" runat="server"/>

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("hd1").value
alert(x)
}
</script>


Mar 8 '07 #3
Thanks both.
I have another question in a new thread and i thing is related to the
predecence ...

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschree f in
bericht news:%2***************@TK2MSFTNGP05.phx.gbl...
OnClientClick always goes first since it happens on client side, when you
view the page in your browser. OnClick happens on the server where the
page
arrives after a postback.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Phil" <ss*******@fff.dfwrote in message
news:Ol**************@TK2MSFTNGP05.phx.gbl...
>Hi,

I'm a little confused about the precedence of actions between
OnClientClick
>and OnClick. In this example, what will be executed first and why?

Thanks
Phil

in code-behind:
---------------
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Hiddenfield1.value="end text"
....
end sub

in aspx file:
----------
<asp:HiddenField ID="hd1" runat="server" value="beginning
text"></asp:HiddenField>
<asp:Button ID="Button1" OnClientClick="test()" runat="server"/>

<script language="javascript" type="text/javascript">
function test()
{
var x = document.getElementById("hd1").value
alert(x)
}
</script>



Mar 8 '07 #4

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

Similar topics

0
by: jtencate | last post by:
I am trying to add an OnClientClick event to links in an asp:Menu. I tried using a StaticItemTemplate to bind the MenuItem data to a LinkButton with an OnClientClick attribute. This works fine to...
2
by: Opa | last post by:
Hi, I have a asp:button which allows a user to delete a record, and I wish to prompt them with a client side confirmation. The javascript confirm messagebox does show and the cancel button is...
5
by: Dan | last post by:
Hi, i try to redirect to another aspx page with jscript. I use "OnClientClick" but nothing happens. I tried two ways. What am i doing wrong? Thanks Dan ....
1
by: GreggaR0und | last post by:
Hi; I am writing VBA in Word. The application is that a Userform opens up from a template in order to acquire user input for the remainder of the form. The Userform has three fields which then...
0
by: sloan | last post by:
Asp.Net 2.0 Inside a repeater, I'm trying to do a linkbutton with a OnClientClick <asp:LinkButton ID="lnbSelect" runat="server"...
2
by: dddan | last post by:
Here's my code: <asp:LinkButton OnClick="DeleteFile" OnClientClick="if (!confirm ('Are you certain you want to delete this file?') ) return false;" runat="server" ID="DeleteButton">DELETE...
1
by: Bogdan | last post by:
Hi, I'm trying to programmatically assign a script to a CancelButton's OnClientClick in a wizard step. I'm doing it in ActiveStepChanged event handler. I'm also assigning scripts to finish and...
2
by: =?Utf-8?B?Y3lydXM=?= | last post by:
Hi everybody, I have created a simple web form which contains a repeater. every item of the repeater has a button to delete the tiem. my web form uses Resource files to globalizing the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.