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 195
1 Afzaal Ahmad Zeeshan 152
2 ProgramFOX 130
3 Maciej Los 130
4 den2k88 80
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,657
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.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