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

How to call javascript from code behind

I am using .Net 3.5, withupdatepanel, Its a registration form based on email availability , I call java script function within the button click function,i try a lot but not working.

Expand|Select|Wrap|Line Numbers
  1. <asp:ImageButton ID="imgbut_save" ImageUrl="images_test/button-save.gif" OnClientClick ="return pagevalidationnew();" runat="server"
  2.                             OnClick="imgbut_save_Click" />
  3.  
  4.   protected void imgbut_save_Click(object sender, ImageClickEventArgs e)
  5.     {
  6.         try
  7.         {
  8. //My application
  9. string script = "<SCRIPT LANGUAGE='JavaScript'> ";
  10.             script += "opacityforoned()";
  11.             script += "</SCRIPT>";
  12.             Page.RegisterClientScriptBlock("ClientScript", script);
  13.  
  14. }
  15. }
May 27 '10 #1
2 2401
Frinavale
9,735 Expert Mod 8TB
Um.... I'm not sure what you're trying to do in your code.
There's some very basic things to understand when doing web development:
  • Some code is executed on the server. This is known as server side code. It is your C#, VB.NET, PHP code. Server side code is responsible for doing calculations, generating HTML, and sending that HTML to the web browser to display to the user.
  • Client side code is executed in the web browser. This code includes things like JavaScript/Ajax. It typically works with the HTML elements that were sent to the browser so that the user doesn't have to wait for the page to post back to the server and do calculations and then return with the HTML.

With this in mind, controls like the Button have 2 aspects to them: client side and server side. When the user clicks a button, first the client side "onclick" event is executed and then (if a script doesn't stop the button from posting back to the server) the server side "onclick" event is executed.

Right now you are mixing up the two...thinking that you can call a client side code from within your server side code. But it doesn't work that way. The two are very separate!


Check out this quick over view of How to use JavaScript in ASP.NET.

-Frinny
May 27 '10 #2
Hi thanks for your reply
i solved this problem by using the following code..


ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "MyScript", "opacityforoned()", true);
May 28 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: George | last post by:
I need to call my visitor tracking script selectively from Code Behind using the following sub, but it gives me an Error on Page. I've removed my account and other information, but the format is...
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...
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
3
by: CW | last post by:
I find it necessary to mix code-behind and non-code behind techniques sometimes. I have utility functions defined in a VB module. Is there anyway for me to call functions defined in VB module...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
3
by: anadimpa | last post by:
Hello all I build a javascript function string in the code behind and register it in the Page_Load of my User Control. I do this because I build the javascript based on some variables that are...
2
by: mikepolitowski | last post by:
Hi folks, I am have been trying to solve this problem for quite some time now and would appreciate any advice. I have been trying to call a code-behind function that is defined in my aspx.cs...
5
by: jason.gyetko | last post by:
I'm using JavaScript to capture a keypress in my web form. Right now all it does is post an alert message box. Is there a way to have it call a function in my VB code behind? All I really want...
2
Inbaraj
by: Inbaraj | last post by:
Sir, I want to call javascript code in Asp.net(C#) page. I have done this before but i forget the keyword to run the javascript in asp.net page.... Help me in this matter.... Thanks...
4
by: sajithkahawatta | last post by:
i want to call a java script function from code behind. in page1.aspx page i placed script' <script language="javascript"> function SetSelected() { infoTextBox.select(); } </script>
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
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,...
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...

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.