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

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

Calling Button,s onclick event in javascript code

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :ASP.Net

 Hi Experts.

I have a Button control in webpage.

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" OnClientClick="test()"/>

When i click on button, i want to check some conditions

View Complete Post

More Related Resource Links

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  

radio button checked changed event not firing with onclick javascript function



I have used below code.

<asp:RadioButton GroupName="grpAssoc" ID="rbtEvery" runat="server" Text="Everyone"
                                                                                    onclick="return doChangeAssociationType(0);" AutoPostBack="True" oncheckedchanged="rbtEvery_CheckedChanged"

but oncheckedchanged="rbtEvery_CheckedChan

Infopath button click event in custom workflow code.


Hi All,

I have designed the infopath form(Init) and integrated with my state machine workflow. i want to access button click event (designed in Infopath form) in my workflow code.

Can you help me.




Calling a button's click event from another buttons click event

I have a button that checks the users serial number entry in a web form and a button that subits the page.  But if the user does not click the checkbutton  I want to  fire the check click event  from the pages submit click event.  Is this possible.  In my submit click event I call this Me.cmdCheck_Click(sender,e) though it does not seem to be firing the click event is there something that I am doing wrong?  

Calling csharp code from Javascript

Hi, Is it possible to call a c# code block from Javascript in Sharepoint 2010? I am using redirects to pages at the moment to achieve the effect, but the results are far from desirable. Any help would be much appreciated.   Cheers, M

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

Checking the calling of JavaScript Code?


Hi Experts.

I am looking for the way to solve my problem. Suppose the following scenario:

You have a simple JavaScript code to connect with server and return some parameters form server and use it in your webpage. Like:

<script language="JavaScript">id=100</script> 

<script language="JavaScript" src="">           

The content of samplecode.js is like this:


                // code here.



When the script is run, some parameters are returned from server and is write into your page. Like: (document.write(parameters) ).

So now You want to use this script more than one time in your webpage. Then each time  is run separately and the parameters are returned in separately call. Like:

<script language="JavaScript">id=101</script> 

<script language="JavaScript" src="">

When the first JavaScript is called,  How can return the all parameters that is returned in separately JavaScript? Or Is there any the way to check to several times the javaScript is called in the page and when jus

No OnClick-events on any button/ImageButtons on any page runs any code




I Simply drag a button from the toolbar onto a new page with a master page and a title, double click it so that I enter the Button1_Click function and sets a breakpoint and add some random code. The breakpoint nor the code never fires. I've tried this on several different pages and controllers, but with the same results: The page reloads, but no code is run.

I Have Tried:

Ive tried with three different webbrowsers with all plugins disabled.

I've tried to turn of Causes Validation, - Nothing changes.

I've tried to clean and Rebuild the project, - Still nothing.

I've tried to create a whole new project, - Does'nt work there either.

Other Information:

A RadioButtonList OnDatabound Event works, but whenever i try to do a Button or ImageButton click event the code for the event never fires. Ive programmed several webapplications in other versions of visual studio and ASP.NET but I have never encountered this problem before.

Breakpoints work in other parts of the code and the compile settings is set to DEBUG.


I am using

* Visual Studio 2010


* MVC 2.

Am I supposed to file a bug report or does anyone out there have a solution?

Many thanks in adv

How can i safe value of variables in javascript code in PostBack event?


Hi Experts.

I need to define some Boolean variables in my javascript code and use them  when  the any onfocusout methods of controls  is fired. Like this:


            Var is_ValidateTextBox1 = false;

            Var is_ValidateTextBox2 = false;

            Var is_ValidateTextBox3 = false;

Function focusout_TextBox1()

{ValidateTextBox1 = true; }


When onfocusout of TextBox1 is fire, I want to set  " is_ValidationTextBox1=true;".  But when the post back is fired from the form, the variable reset to false because the line of defining the "Var is_ValidateTextBox1 = false;" is run again in post back!

Now how can I to solve this problem? How can i safe value of variables in javascript code in PostBack event?

With Regards. Mojtaba

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

Button OnClick event not working.


Hi folks,

I am having trouble with two buttons on a page. I dragged them on to the page and then double- clicked each of them in order to create the OnClick events.

I added my code to the events, but when I click the buttons, their respective events aren't being called.

I am very confused!

Any help is appreciated, thanks!

My .aspx code:

<asp:Button ID="Button3" runat="server" Text="Accept" CausesValidation="true" onclick="Button3_Click" />
        <asp:Button ID="Button4" runat="server" Text="Reject" CausesValidation="true" onclick="Button4_Click" />

My Code behind:

protected void Button3_Click(object sender, EventArgs e)
        int id = int.Parse(queryString);

        #region LiveDatabase
        //string connection = ConfigurationManager.ConnectionStrings["LiveDatabase"].ToString();

        #region MySqlDatabase
        string connection = ConfigurationManager.ConnectionStrings["MySqlDatabase"].ToString();

        MySql.Data.MySqlClient.MySqlConnection MyConn = new MySql.Data.MySqlClient.MySqlConnection(connection);

        string query = "UPDATE p

Problem with calling asp button click event from Java script


Dear all ,


I m using these following lines of codes in my java script funtion Save()




var btnSave = document.getElementById('<%=btnSave.ClientID%>');


In ascx,

<asp:Button runat="server" style="display:

Button onClick event not firing in Safari 5


Hello All.

I'm am fairly new to ASP.NET and have been experiencing quite an odd problem.  My application works just as I expect it to in IE7 and FF. However, once tested in Google Chrome or Safari, I start to experience issues with the firing of my onClick event.  In Chrome or Safari 4, when I click my button control, it does not seem to recognize that the button has been clicked at all and my onClick event is never fired.  However, upon clicking it a second or third time, it fires.  Annoying.  The real problem is with Safari 5.. No matter how many times I click the button, nothing happens.. Yet I have found that if I tab down to the button and select it using the space bar, it fires... ?? So, I have done a great deal of digging and have found very few posts that describe something similar.  I have read that Chrome and Safari report themselves as WebKit in their userAgent strings, but I believe that only comes into play when using AJAX.  


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

disable button in page load click event using javascript



i have button its  enable false in aspx page, if i click the page load  click event  then button should enable

looking forward the reply.

Calling Javascript functions in VB.net code



This is the javascript function and I'm calling this method in my vb.net code. The jsfunction printPageZB works fine but function printPage() prints only 1 page, i want 2 pages printed. What am i doing wrong here.....any suggestions?

function printPageZB() {



function printPage() {

document.getElementById('pnlPhotoBook').style.display = 'none';


document.getElementById('pnlPhotoBook').style.display = 'block';




vb.net code

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim jsr As String = "<script type='text/javascript'>printPage();</script>"

Dim jsr2 As String = "<script type='text/javascript'>printPageZB();</script>"

If pnlPhotoBook.Visible = True Then

If (Not IsStartupScriptRegistered("Startup")) Then

RegisterStartupScript("Startup", jsr.ToString)

End If


If (Not IsStartupScriptRegistered("Startup")) Then

RegisterStartupScript("Startup", jsr2.ToString)

End If

End If


Problem in calling javascript function from code behind


Hi All,

  how can i call Javascript function on Button click after doing some server side operation?

  Though i am using ClientScript.RegisterStartupScrip(), sometime it is working(for alert) but when i am using for display confirm message it is not showing Confirm message.

ClientScript.RegisterStartupScript(GetType(), "ConfirmMessage", "javascript:return ConfirmMessage('" + lMessage + "');");

this is not working.

Please help me out.

Thanks & Regards,



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" />







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