473,699 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with onclick/onserverclick with hjtmlbutton

Hi,

I defined a Html button but added the option 'runat="server" ' like this:
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="hfd()" />
</form>
<script language="javas cript" type="text/javascript">
function hfd()
{alert("ok")}
</script>

This works.

But if i add the function 'button1_click' in the code-behind like this:
Protected Sub Button1_ServerC lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.ServerC lick
Response.Write( "ok from server")
End Sub

I expect first the Alert and then the response.write message, but I get the
javascript error: expected: ';' and nothing is shown.

Is it not possible to do a client-event and a server-event together?
Thanks for help
Phil
Jun 5 '06 #1
4 5806
Hi,

I tried your scenario:

the input I added had this:

onclick="alert( 1);"

when rendered by the server it had this:

onclick="alert( 1); __doPostBack('B utton1','')"

It did show the alert and then did the postback. So yes it is possible.

I think you probably have a different javascript error somewhere else in
your page.

Is the error, javascript error: expected: ';' giving you a line number?
It should. You might have to turn on more of your browser's debugging
features to see it.

I would do a view source on the rendered page and try to find the real
javascript error.

mnichols
phil wrote:
Hi,

I defined a Html button but added the option 'runat="server" ' like this:
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="hfd()" />
</form>
<script language="javas cript" type="text/javascript">
function hfd()
{alert("ok")}
</script>

This works.

But if i add the function 'button1_click' in the code-behind like this:
Protected Sub Button1_ServerC lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.ServerC lick
Response.Write( "ok from server")
End Sub

I expect first the Alert and then the response.write message, but I get the
javascript error: expected: ';' and nothing is shown.

Is it not possible to do a client-event and a server-event together?
Thanks for help
Phil

Jun 6 '06 #2
Yes, you're right.
My fault was that i forgot to put ';' in onclick="hfd()" .
Thanks
The Javascript error message mentioned line 35, but there is only 21 lines
in the aspx file ..So it's hard to find the error ...
"mnichols" <mn************ ****@yahoo.ca> wrote in message
news:en******** ******@TK2MSFTN GP02.phx.gbl...
Hi,

I tried your scenario:

the input I added had this:

onclick="alert( 1);"

when rendered by the server it had this:

onclick="alert( 1); __doPostBack('B utton1','')"

It did show the alert and then did the postback. So yes it is possible.

I think you probably have a different javascript error somewhere else in
your page.

Is the error, javascript error: expected: ';' giving you a line number?
It should. You might have to turn on more of your browser's debugging
features to see it.

I would do a view source on the rendered page and try to find the real
javascript error.

mnichols
phil wrote:
Hi,

I defined a Html button but added the option 'runat="server" ' like this: <form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="hfd()" />
</form>
<script language="javas cript" type="text/javascript">
function hfd()
{alert("ok")}
</script>

This works.

But if i add the function 'button1_click' in the code-behind like this:
Protected Sub Button1_ServerC lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.ServerC lick
Response.Write( "ok from server")
End Sub

I expect first the Alert and then the response.write message, but I get the javascript error: expected: ';' and nothing is shown.

Is it not possible to do a client-event and a server-event together?
Thanks for help
Phil

Jun 6 '06 #3
The line number (35) refers to the rendered page not the original source
So you have to view the page in the browser, then view the rendered
source from the browser and then find line number 35 in it.

Also, normally onclick="alert( 1)" would be fine, but because ASP.NET is
adding code to the event onclick="alert( 1);" is required. (One might
think that ASP.NET would have inserted the semi-colon for you just to
play it safe since two semi-colons would be harmless.)

mnichols

phil wrote:
Yes, you're right.
My fault was that i forgot to put ';' in onclick="hfd()" .
Thanks
The Javascript error message mentioned line 35, but there is only 21 lines
in the aspx file ..So it's hard to find the error ...
"mnichols" <mn************ ****@yahoo.ca> wrote in message
news:en******** ******@TK2MSFTN GP02.phx.gbl...
Hi,

I tried your scenario:

the input I added had this:

onclick="alert( 1);"

when rendered by the server it had this:

onclick="alert( 1); __doPostBack('B utton1','')"

It did show the alert and then did the postback. So yes it is possible.

I think you probably have a different javascript error somewhere else in
your page.

Is the error, javascript error: expected: ';' giving you a line number?
It should. You might have to turn on more of your browser's debugging
features to see it.

I would do a view source on the rendered page and try to find the real
javascript error.

mnichols
phil wrote:
Hi,

I defined a Html button but added the option 'runat="server" ' like this: <form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="hfd()" />
</form>
<script language="javas cript" type="text/javascript">
function hfd()
{alert("ok")}
</script>

This works.

But if i add the function 'button1_click' in the code-behind like this:
Protected Sub Button1_ServerC lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.ServerC lick
Response.Write( "ok from server")
End Sub

I expect first the Alert and then the response.write message, but I get the javascript error: expected: ';' and nothing is shown.

Is it not possible to do a client-event and a server-event together?
Thanks for help
Phil


Jun 6 '06 #4
Thanks again..

"mnichols" <mn************ ****@yahoo.ca> wrote in message
news:OC******** ******@TK2MSFTN GP02.phx.gbl...
The line number (35) refers to the rendered page not the original source
So you have to view the page in the browser, then view the rendered
source from the browser and then find line number 35 in it.

Also, normally onclick="alert( 1)" would be fine, but because ASP.NET is
adding code to the event onclick="alert( 1);" is required. (One might
think that ASP.NET would have inserted the semi-colon for you just to
play it safe since two semi-colons would be harmless.)

mnichols

phil wrote:
Yes, you're right.
My fault was that i forgot to put ';' in onclick="hfd()" .
Thanks
The Javascript error message mentioned line 35, but there is only 21 lines in the aspx file ..So it's hard to find the error ...
"mnichols" <mn************ ****@yahoo.ca> wrote in message
news:en******** ******@TK2MSFTN GP02.phx.gbl...
Hi,

I tried your scenario:

the input I added had this:

onclick="alert( 1);"

when rendered by the server it had this:

onclick="alert( 1); __doPostBack('B utton1','')"

It did show the alert and then did the postback. So yes it is possible.

I think you probably have a different javascript error somewhere else in your page.

Is the error, javascript error: expected: ';' giving you a line number?
It should. You might have to turn on more of your browser's debugging
features to see it.

I would do a view source on the rendered page and try to find the real
javascript error.

mnichols
phil wrote:
Hi,

I defined a Html button but added the option 'runat="server" ' like

this:
<form id="form1" runat="server">
<input id="Button1" type="button" value="button" runat="server"
onclick="hfd()" />
</form>
<script language="javas cript" type="text/javascript">
function hfd()
{alert("ok")}
</script>

This works.

But if i add the function 'button1_click' in the code-behind like this: Protected Sub Button1_ServerC lick(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Button1.ServerC lick
Response.Write( "ok from server")
End Sub

I expect first the Alert and then the response.write message, but I
get the
javascript error: expected: ';' and nothing is shown.

Is it not possible to do a client-event and a server-event together?
Thanks for help
Phil


Jun 6 '06 #5

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

Similar topics

2
478
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 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.
1
6450
by: Krishna | last post by:
1. What is the difference between OnClick and OnServerClick in web button control If I have a asp button control as follows <asp:button id="SubmitOrder" Text="Submit Order" OnClick="OnSubmit_Click()" runat="server" > </asp:button> If the above is going to fire server side function what is
1
1101
by: shimmer | last post by:
Hi i have this code, which when i click the button ( just an example), the span doesnt change...Can some1 help me ~ . I am thinking of could it be the problem of the button. There is no response of the button event...can anyone give me some advise pls.. <Form Runat="Server"> <Button Id="Button1" Runat="Server" OnServerClick="Button1_Click"> change</Button><BR> </Form>
2
1532
by: Sandeep | last post by:
Hi I want to write onclick event on a button(a web control) ,also i want to call a client side function on the click event how to write that how to differentiate between these two events Will it be like that <asp:button id="ss" onclick="javascript:ss()" onserverclick="btn_click()">
2
2068
by: tao lin | last post by:
Hi, all I am using VS2003 under WinXP. My WebApp has a WebForm which has a html form has some search condition textbox, once the user fill in the condition and click submit button. My app will stay in the same WebForm but open a popup window in the browser to show the search results. So I implement like this: private void btnSubmit_Click(object sender, System.EventArgs e)
2
2197
by: COHENMARVIN | last post by:
I have a form with a Submit button. The user fills out the form, clicks the submit button, and then the page posts back to itself. Every time the page posts back to itself, the "Page_Load" event fires. So if the user first types the URL of the page in the browser, the "Page_Load" event fires. Then he hits submit, and the form contents are posted back, so the "Page_Load" event fires again. The form appears again (I clear its contents),...
8
2495
by: -Karl | last post by:
Snippet: http://www.nomorepasting.com/getpaste.php?pasteid=1020&seen=true&numbered=on&langoverride=asp Line 37 is where I am having the problem. I can't get the onclick event to fire off. Yet line 16 works like it's supposed to. How do I get my onclick event to work? I tried changing it from onclick to onserverclick but that had no effect. Thanks!
6
10003
by: Bhavs | last post by:
HI All, I am having a client side code : <asp:HiddenField ID="hiddenfield1" runat="server" Value='<%# Eval("Id") %>' /> <a runat="server" id="hlViewPropertyAddressDetail" onserverclick="logstats(hiddenfield1)"> and in the Code Behind i have a logstats function as public void logstats(string id) { ....
2
3770
by: GuruPrasadBytes | last post by:
I am opened window.open(child.aspx page) from the parent.aspx file the below code is from parent.aspx, <HTML> <HEAD> ...... </HEAD> <body onload="loadXML();"> ..... <input id="AddSecurityBtn" type="button" runat="server" onclick='javascript: Args = objDoc.selectSingleNode('//Books'); Args = buildBookTable ; Args =null; window.open('child.aspx','800','900');' value="Add Books" />
0
8615
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8911
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6533
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5872
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2345
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.