Solved

Script won't work at VS2003

Posted on 2004-03-29
10
203 Views
Last Modified: 2010-04-06
hi there,
we got this VS 2003, I can't manage to run a script from it always the same error "CS1026: ) expected",
I can't run the most simple script for a button click "onclick"
can any1 help plz?
10x
0
Comment
Question by:orenisraeli2000
10 Comments
 
LVL 9

Expert Comment

by:lombardp
ID: 10703460
Could you post your code?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10703747
the problem is that if you are using asp.net, the button is always rendered as a submit button. In order to add an onclick event through the server code you must first cancel the postback
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10703776
try adding an onClick event through the server code:

myButton.Attributes.Add("onclick","myFunction()")
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 10704844
I'm using VS203,ASP.NET,WinXP
how to I cancel postback?

well I don't know, look I'm trying with the a very simple code:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"  %>
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
      <body MS_POSITIONING="GridLayout">
      <script language=javascript >
         function x(){
         writeln("fsdfds");
         }
      </script>
      <form id="Form1" method="post" runat="server">
           <asp:Button id="Button1" runat="server" Text="Button" OnClick="javascript:o();" ></asp:Button>
      </form>
      
      </body>
</HTML>
nothing work, I've tried to call the function by many variations, nothing helps...
when I put a new buton on a new page under a new project . there is no "View Client Script"
10x
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10706659
get rid of  OnClick="javascript:o();" inside <asp:Button> tag

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"  %>
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
     <body MS_POSITIONING="GridLayout">
     <script language=javascript >
        function x(){
        writeln("fsdfds");
        }
     </script>
     <form id="Form1" method="post" runat="server">
          <asp:Button id="Button1" runat="server" Text="Button" ></asp:Button>
     </form>
     
     </body>
</HTML>

then open your code behind file -WebForm1.aspx.cs

have this line:

Button1.Attributes.Add("onclick","javascript:o();" );

inside Page_Load procedure
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:YZlat
ID: 10706764
I'm sorry, it should be

Button1.Attributes.Add("onclick","javascript:x();" );
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 10712404
well hi again,
if I change the button to an <input type=button ...../>
I manage to call a javascript function, but when trying to do it with <asp:button ..../>
no chance
in inlights?


PS
I guess for you efforts I increased the points
thank you
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 10712617
msdn tells me the same for catching <asp:button...> onclick event I need to add a line
"Button1.Attributes.Add("onclick","javascript:x();" );" but doing so I get nothing there are no errors no response nothing
0
 
LVL 2

Accepted Solution

by:
kulpem earned 500 total points
ID: 10881268
I think you just have an error or a logic problem
I know the problem.
as I see u use another file for the server side scripting, thats good. for calling these function just use "on_click=printMe" no "()" nothing.
for javascript write it on the asp page again like this "onclick=markme"
it will work
enjoy
0
 
LVL 1

Author Comment

by:orenisraeli2000
ID: 10881283
i think its better
no one ones i guess
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Migrating to Exchange 2013 4 41
My first jQuery plugin: is the right tutorial missing? 2 82
CSS display:none AND display:block on same element 3 77
SP to delete duplicates 15 60
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now