how to call Datagrid onblur function in our aspx page using javascript




 i want to calculate the datagrid inside textbox total value  by calling javascript onblur function...

thanks in advance



9/26/2007 12:00:43 PM 24353 articles. 2 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 16

in code behind...add this... 

protected void Page_Load(object sender, EventArgs e)



if ((this.Request.Params["__EVENTARGUMENT" ] == "DataGrid_OnBlur(Sender, e)"))


DataGrid_OnBlur(Sender, e);


in javascript

__doPostBack('', 'DataGrid_OnBlur');

where DataGrid_OnBlur is the name of the server side function



Vishal Khanna

(pls mark as answer if reply helps) 


Vishal Khanna
.NET Interviews & FAQs @

Click Mark as Answer if the reply helped you.
9/26/2007 12:45:29 PM

i want to calculate the datagrid inside textbox total value  by calling javascript onblur function...

Hi deepaimman,

Based on my understanding, you want to count the value of the textbox control in each row of DataGrid control with the onblur event. If I have misunderstood your concern, please let me know.

For this requirement, I have provided the following code for your reference. I hope it is helpful to you.

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">

        function Calculate()
            var totallabel;
            var datagridid = '<%= DataGrid1.ClientID %>';
            var labels = document.getElementsByTagName('span');
            for (var i=0; i<labels.length; i++)           
                if (labels[i].id.indexOf(datagridid) != -1 && labels[i].id.indexOf('TotalLabel') != -1)
                    totallabel = labels[i];

            var textboxes = document.getElementsByTagName('input');
            var count = 0;
            for (var i=0; i<textboxes.length; i++)
                if (textboxes[i].type == 'text' && textboxes[i].id.indexOf(datagridid) != -1)
                    var floatvalue = parseFloat(textboxes[i].value);
                    if (floatvalue != 'NaN')
                        count += floatvalue;
                        totallabel.innerHTML = 'Total: NaN'
            totallabel.innerHTML = 'Total: ' + count;
    <form id="form1" runat="server">
        <asp:DataGrid ID="DataGrid1" runat="server" ShowFooter="True" AutoGenerateColumns="false">
                <asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
                        <asp:TextBox ID="TextBox1" runat="server" onblur="Calculate()"></asp:TextBox>
                        <asp:Label ID="TotalLabel" runat="server" Text="Total: "></asp:Label>

********** code behind
        DataTable table;
        protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
                table = new DataTable();
                table.Columns.Add("Name", typeof(String));
                DataGrid1.DataSource = table;


Benson Yu
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.
10/2/2007 2:42:52 AM

Similar Artilces:

How to call server side(C#) function from Client side(Javascript) function?
Hi i have used below functions,  function HandleOnClose() {// this function will be called after clicking browsers close button in Internet explorer if (event.clientY < 0) { event.returnValue = 'Are you sure you want to leave the page?'; } // if he clicks ok then i need to call one server side function in this instance.. else not. } <body onbeforeunload="HandleOnClose()" leftmargin="0" rightmargin="0">other controls in page..</div>  How to achieve this? Thanks MS AJAX Extensions would be the option of choice here. Combined with webservices you can...

Call codebehind method from aspx page OR call javascript function of usercontrol control from page
Hi, I have a page which contains a user control.  When a user clicks on a submit button, I'd like to detect when elements in the user control have changed and popup a message box if changes have been detected to confirm if the user wants to save the changes. Obviously the message box is executed using javascript.  But I'd really like to be able to call a method in the code behind of the page which queries the user control if it has changed.  Is there a way of calling the code behind method from within a javascript function? Otherwise, if I make all the functions execut...

How to call server side function by javascript using Ajax.Net
Sir, I want to call the server side function by javascript function. Is it possible using Ajax.Net (System.Web.Extensions.dll or AjaxControlToolkit.dll)? If yes then please give me the code or URL. I found some article using Ajax.dll but I want to use System.Web.Extensions.dll or AjaxControlToolkit.dll. Please help me. Thanks in advance Paresh        Hi, Ajax.NET and ASP.NET AJAX, what you want, are completely different implementations so please be sure to use the correct terminology in the future as there are already 100+ AJAX frameworks aroun...

Calling a Form Code-Behind function using Javascript from the Client Side
Hi,Is there any way to call a function in the form codebehind from the client side using javascript? If yes, how? How to send parameters?Thanks. Try reading this article.  It is kind of the opposite of what you are trying to do but maybe it will help. this helps,MattADV do a view source on the page and you most liekly will see a do post back function. You can call that with JavaScript and it forces the page back. You can send parameters back by placing them inside of hidden form e...

Call server side function from client side javascript
I have a javascript where I either need to call an onclick even of a server link button or I need to be able to call a server side function.   The only thing is I cant use AJAX.  Is there any way I can do this or am I spinning my wheels. Thanks!-------------Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue. I have a similar problem.  In my case, I would like to set a server-side session object from JavaScript.  Any suggestions?  Thanks.  Dan Sure, y...

how to call server side function from client side javascript?
Hi all, I have a image button in the update panel. I would like to call a method from server side (not from webservice) to get the variable when Onclick on the image button is invoked. Is there any way that I can able to access this function from the client script? In using the UpdatePanel, in essence, you're already doing this because there will not be a full postback.  You can make an asynchronous call to your Click method of your ImageButton.  So, what do you want to do with this "variable"?Christopher Reed"The oxen are slow, but the earth is patient."...

How to call server side function from client side JavaScript?
I want to call a server-side function, like a button's click event or just another private or public function , from a client-side JavaScript function. How do I do that? thanX AnzIf this post was useful to you, please mark it as answer.ClientSideAsp.Net | Blog Maybe alittle more that you need, but....... 1) Put a button on the page. Lets say its id is Button1. Make sure that its has causesValidation=false 2) Write the code for the button. 3) Write the following in the PAge_Load event Button1.Attributes.Add("onClick", "myJSFunction(); return false") 4) Copy this javascript...

Setting width for .net controls in code(.aspx) page using function call in code behind..
Hi,  Currently I am trying to set the width of the Table as follows. <asp:Table width="<%=GetWidth()%>" >   and code behind protected Unit GetWidth() { return Unit.Percentage(50); }     It's not working. I know that it works if I set the width complete on some page event(like page_load) of code behind....   Is there a way to maintain the same syntax like calling code behind function in design page...i.e. calling function of .aspx.cs in .aspx page and assign the width as shown above.   Thanks and regards, Giridhar...

Call a javascript function from a report, the function is in aspx page
Hi    How can I go about calling a javascript from from a report. The function is in teh code behind aspx page. When a user clicks a link on the report, this function needs to be called. Further, the report sits in an iframe of the aspx page. So somehow I need access to the aspx page without opening any other pages. I tried using this ="javascript:void SelectTab('tabScoreCard',EnergyExpert_" + Fields!EnergyExpertKey.Value.ToString() + "')"  but that gives me an error of no object found, when the user hits the link on the report to go back t...

Calling a server side function from client side using the toolkit
Ok, I'm sure this is a really stupid question, but I'm willing to ask it anyway.  Let's say that I created a new extender called "My", so I now have three files files, MyExtender.cs, MyBehaviour.js, and MyDesigner.cs.  I want my control to be able to take some data on the client side and use it to retrieve some data on the server side, which AJAX is all about right? :) So for the sake of argument, let's say I want to enter an email address in a textbox, and then consult a database to return the user's password. So in my MyExtender.cs file, I create ...

Call server-side page function from client-side button click
I have an existing ASP application that I am migrating to In the ASP app I was using the Microsoft.XMLHTTP on a the client-side of a ASP page to retrieve data from another asp page using the Microsoft.XMLDOM object. The client page passes 3 tags columns, table and Criteria. The receiving page builds the SQL statement executes the query and returns the row with all the column data. I am trying to convert it over to ASP.NET and I am getting errors on the xmlDOM.Load(Request.InputStream) on DLookup.aspx, the code is listed below. Someone suggested to use System.Net HTTP classes su...

Can you call a c# on the server side from javascript functions on client side
Hello guys This is something intresting I have come across during development. I have a javascript written in a .JS file , to my knowledge the .js files are executed on the server side. But security concerns with java script that these .js files can be access by connecting to port 80 of the server . So an ultimate alternative reminas to call c# code from a java script function. Can anyone Help me on this matter Regards Nihar Hi Nihar, Usually .js files executed on client side. Please explain your configuration.Leon LangleybenMCSD, ASP.NET MVPBlog...

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

Accessing server-side control in client-side javascript function; on Content page
I am trying to set an asp:textbox value in the Client side javascript function. It works fine on the standalone page. But when i try to do this the Content page, it’s giving the follwoing error message. document.getElementByID[...] is null of not an object  Any idea? Thanks, Riz   Hi, are you using ClientID property of that server control, to get its ID (which is rendered at the client and can be used with document.getElementById )?Thanks,Teemu KeiskiFinland, EU Thank you my problem is solved....

Web resources about - how to call Datagrid onblur function in our aspx page using javascript -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

Lightbox (JavaScript) - Wikipedia, the free encyclopedia
On a Lightbox-enabled page, a user can click an image to have it magnified in a Lightbox window, which resizes itself according to the size of ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
about dmoz - help Top : Computers : Programming : Languages : JavaScript : Tools : Obfuscators Tools for obfuscation/compression JavaScript code. ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 12/27/2015 1:37:18 AM