Click here to Skip to main content
13,147,037 members (60,131 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How to call code behind functions or methods of from javascript? From javascript i need reload my datagrid by calling this function "fillgrid()" which i have written in my code behind.
Posted 27-Jun-13 22:02pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

you need something like this, that trick is

For example:

1. Add this html code

<asp:TextBox ID="txtinput" runat="server" onblur="doPostBack();"></asp:TextBox>
<asp:UpdatePanel ID="niceTrick" runat="server">
<asp:Button ID="btnpostback" runat="server" Text="btnpostback" onclick="btnpostback_Click" style="display:none" />
<asp:label id="lbltxtchange" runat="server" xmlns:asp="#unknown"></asp:label>

2 . Add this javascript code

 <script type="text/javascript">
<pre lang="xml">function doPostBack() {
    document.getElementById('<%=btnpostback.ClientID  %>').click();


3. Finally add this code into your code behind file

protected void btnpostback_Click(object sender, EventArgs e)

regards and thanks
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can not call a server side function in client side scripts, Two solution is available for you
1. Reload whole of page by
or post back the page by a ASP.NET control.

2. Use Ajax technology
My recommend is using the built-in Ajax in ASP.NET.
Put your DataGrid into a UpdatePanel from Ajax extension controls then you can update it asynchronously.
for more info please search your favorite search engine with keyword "ASP.NET Ajax controls"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 1 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100