.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Unable to call javascript function through button's click

Posted By:      Posted Date: October 04, 2010    Points: 0   Category :ASP.Net


i have a javascript function that is placed in a separete file.There are some other functions also.

On a Button's OnClientClick i want to call a javascript function, but it is not called.When i put the same function in my aspx page that function is called. So how can i call that function which is placed in another .js file.

I  have taken some other controls like radio button , that is working fine when i call some functions  that is placed in the same .js file.

I have written like this in Button's OnClintClick property:



View Complete Post

More Related Resource Links

How to call javascript function from Button CLick event



I have a createuserwizard. My CompleteUserWizard in CreateUserWizard is like this..

<asp:CompleteWizardStep ID="MessageStep" runat="server">





  <table style="height: 100%; width: 100%;">


   <td align="center" colspan="2" class="complete_text">






  Your account has been successfully created.




     <td align="center" colspan="2">

    <asp:Button runat="server" ValidationGroup="Createuserwizard1" CommandName="Continue" ID="ContinueButton" CausesValidation="False" Text="Continue" Width="65px" CssClass="Base" />







I am unable to invoke the CheckPassword() function on button click event.


i have written one javascript function to compare two password fields , to compare password with confirm password field but when I am trying to debug it give me the following error message

  'ASP.default_aspx' does not contain a definition for 'CheckPassword' and no extension method 'CheckPassword' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?)

please see the code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <script type="text/javascript" language="javascript">
 function CheckPassword()
 var password;
 var confirmpassword;
 var msg;

Can you call a javascript function from code behind?

Call you cal a javascript function from the code behind? If so how??? 

Can you call Javascript function from the codebehind?

 Can you call Javascript function from the codebehind?  How???

Viewstate issue when calling button click event from Javascript

I have a javascript that asks a confirmation on search click. If the user has made some changes to the data in grid (gridview) on click of Search, a confirmation is asked to Save or Continue Search. If Yes, Save the records by invoking Save click from javascript. If No, Search click is invoked. While Search click happens correctly, Save click results in an error which reads like this..  "Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster. " I know the Viewstate is what causing the problem, where the control is not loaded but script is trying to invoke it's click event. Any help is appreciated. At the end of the day, all i need is to invoke Save click from javascript.   -- Viswanth VG  

How to call javascript function in master page

helloi have javascript file 'script.js' where i have writt en a function for print. but this function is working fine if i am not using master page in my report page but the question is i want to use master page for my report page where i am calling javascript function but it is not working . Do help me regarding MasterPage and Javascript function.

asp:Button inside a SharePoint Dataview's Rows with onclick event does not call C# function. Pull i

asp:Button inside SharePoint Dataview Rows with onclick event does not call C# function. Pull it out of Dataview and works fine. I have a ASP.NET Button I've placed inside a SharePoint  DataView's rows with an onclick event pointing to C# function block inside my page. The page refreshes when I click on them, but it's not hitting that code block. If I move the button to outside the dataview and make the ID fixed, the code works beautifully. what's up with that? the button in the Dataview: td class="ms-vb" style="width: 70px"><asp:Button runat="server" Text="Delete" id="Delete{@ID}" CommandArgument="{@FileRef}" OnClick="DeleteDoc"/> </td> my C# onclick handler (inline C# on the page) void DeleteDoc(object sender, EventArgs e) { Button b = sender as Button; .. more code The buttons are rendered and they look like this: input type="submit" name="ctl00$PlaceHolderMain$g_08acadfd_957b_4112_a426_cc7c81991c1e$Delete1" value="Delete" id="ctl00_PlaceHolderMain_g_08acadfd_957b_4112_a426_cc7c81991c1e_Delete1" Thie code block in inline and I'm working from SharePoint Designer. Not sure how I can troubleshoot this.  Am I missing something here, maybe I need to add an Itemtemplate or something like we need to in the ASP.N

Asp.net MVC: How to call javascript function in Html.ActionLink

When I edit single recored in page, I use checkbox to get a selected row not every row with an actionlink element, but it seemed I cant make this way happen through calling javascript code(function GetSelectedRow() should return an id). Could anyone have a nice idea?<head runat="server"> <title>Index</title> <script type="text/javascript" language="javascript"> function GetSelectedRow() { var a = 0; var chkBoxes = document.getElementsByName("chkSelect"); var count = chkBoxes.length; for (var i = 0; i < count; i++) { if (chkBoxes[i].checked == true) a = chkBoxes[i].primaryKeyID; } return a; } </script> </head> <body> <div> <span style="width:20%"> <%: Html.ActionLink("Add", "Create")%> </span> <span> <%: Html.ActionLink("Edit", "Edit", new { id = GetSelectedRow()) %> </span> <span> <%: Html.ActionLink("Detial", "Details", new { id = GetSelectedRow() })%> </span> <span> <%: Html.ActionLink("Delete", "Delete", new { i

Javascript in Datalist .... on click of Button Show details in Another DIV

Hello Experts My Question is how to Set / call javascript in a Datalist , Where to define / Add Attrbutes for that / My Functionatilty requires on click of a button i have to show details in another DIVThanks ... Any Code Example is Much appreciated .. Thanks

Call a javascript function from.Net

Hi,I want to be able to open a new window using javascript.  I know how to do this when it's inline code but it's not too neat as the html built contains lots of reused data.Ideally what I would like to do is, register a function using .Net then call it from my code.  It doesn't help that I'm not too familiar with how to pass parameters to a javascript function in the first place.Anyone help?ThanksJohn

error calling javascript function in asp link button


I am using a asp link button in grid template field which calls a pop up,i need to find the link button's control in cs page.

my link button code

<asp:LinkButton runat="server" ID="hlQName" Text='<%# Eval("QuestionnaireName")%>' OnClientClick

How to call a button click event on from an event handler



I got an event handler like this, in this event, i wanted to call another button click event. How can I do that?

protected void gwDetail_SaveCommand(object sender, System.EventArgs e)
            lblMsg.Text = "Saving...";


if (ds.Tables[0].Rows.Count == 0)

Call Javascript method on Click


Hi ,

I want to call Javascript method on Linkbutton click.

How i can do this.

I m trying this-:

StringBuilder sb = new StringBuilder();
                sb.Append("<script language=javascript>");
                ScriptManager.RegisterStartupScript(this.Page, GetType(), "test", sb.ToString(), false);

it's doning well but given some probs so tell me another way.

how to call button click event of ascx page in the button click event of aspx page



i'm using user control in my page.i need to call the button click event of user control in the button click event of aspx page based on some condition.is it possible?can any one help me?

Javascript function call in HTML+VB?


Hi, i try to call a VB.NET function in my HTML body tag

<body onunload = "if (screenTop > 9999) call Session_End;">


Where Session is my Public VB.Net function in the Global.asax but nothing happen. Do I have to write something like "<script type=\"text/javascript\">?.


How to call a javascript click event from ASPx?


this is kind of wierd but I need to use behindcode or aspx code to call a javascript click event.  The reason is because, I have two controls.  One control is a javascript controls tabs.  The other control is a panel.  The panel has a bunch of controls and depending on which tabs are being selected, the panel will switch to panel1,2,3,4 depending on if the user click tab1,2,3,4.

I've got the upper part programmed by using a __doPostback to the update panel.

However, in this case, I need to program the opposite because when the user switches the panel, the tab must be switched.

So here's what I got when a user clicks the tabs:

<a href="#" onclick="easytabs('1', '1');__doPostBack('UpdatePanel2', 'Tab1');return false;" onfocus="easytabs('1', '1');" title="" id="tablink1">

So I need a server side function such that when a user clicks <asp:LinkButton> or something, it will also call "easytabs('1','1');

How "Call a function" from Message box Ok button and how to add "Cancel button" in Message box


Dear Members,

               I have used the following codings to display the message box.

            StringBuilder sb = new StringBuilder();
            sb.Append("<script type = 'text/javascript'>");
            sb.Append(" Do you want save following records...');");
            ClientScript.RegisterStartupScript(this.GetType(), "script", sb.ToString());

              My requirment is to use the "Ok" button in the message box(alert box).

               I have a function Save().

               I mean if i click on the OK button in the message box, then it should call "Save()"  function.

               And also

               I need to add one more button : Cancel in the message box(alert box)

               Please give a hint.            


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend