Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET4.0
How to call code behind functions or methods of asp.net 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 23:02pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,
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">
<ContentTemplate>
<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>
</ContentTemplate>
</asp:UpdatePanel>
 
2 . Add this javascript code

 
 <script type="text/javascript">
<pre lang="xml">function doPostBack() {
    document.getElementById('<%=btnpostback.ClientID  %>').click();
}
</script>  
3. Finally add this code into your code behind file
 
protected void btnpostback_Click(object sender, EventArgs e)
{
  lbltxtchange.Text=txtinput.Text;
}
 
regards and thanks
sarva
  Permalink  
Rate this: bad
good
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
window.location.reload()
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"
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 381
1 Praneet Nadkar 237
2 Marcin Kozub 225
3 Sergey Alexandrovich Kryukov 200
4 Shweta N Mishra 161
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 1 Jul 2013
Copyright © CodeProject, 1999-2014
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