2

i am looking to set sorting on ASP Repeater. see my repeater code:

 <asp:Repeater runat="server" ID="RptClientDetails">
                    <HeaderTemplate>
                        <table id="example" class="dynamicTable table table-striped table-bordered table-primary">
                            <thead>
                                <tr>
                                    <th>

                                 <a href="#" onclick="ClientSort('ClientID')">Client ID</a>


                                    </th>
                                    <th>
                                     <a href="#" onclick="ClientSort('Name')">Name</a>


                                    </th>
                                    <th>
                                     <a href="#" onclick="ClientSort('TotalBalanceDue')">Total Balance Due</a>


                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                    </HeaderTemplate>
                    <ItemTemplate>

here, i am calling javascript function. see my javascript function code:

function ClientSort(SortExpress) {

           <%= Sorting(SortExpress) %>
         }

from here i want to call my .net server side function.

public void Sorting(string SortExpression)
{
    string s = SortExpression;

}

so, have you idea how can i call it? or directly from repeater i can call this server side function..Thanks

4 Answers 4

2

Directly you can call server side code from repeater control, just use Linkbutton instead of href.

<asp:Repeater runat="server" ID="RptClientDetails">
   <HeaderTemplate>
            <table id="example" class="dynamicTable table table-striped table-bordered table-primary">
                <thead>
                    <tr>
                        <th>
                            <%--<a href="#" onclick="ClientSort('ClientID')">Client ID</a>--%>
                            <asp:LinkButton ID="lbtn" Text="Client ID" ForeColor="Blue" OnCommand="lbtnSorting_Click" CommandArgument="ClientID" runat="server"></asp:LinkButton>
                        </th>
                        <th>
                            <asp:LinkButton ID="LinkButton1" Text="Name" ForeColor="Blue" OnCommand="lbtnSorting_Click" CommandArgument="Name" runat="server"></asp:LinkButton>
                            <%--<a href="#" onclick="ClientSort('Name')">Name</a>--%>
                        </th>
                        <th>
                            <asp:LinkButton ID="LinkButton2" Text="Total Balance Due" ForeColor="Blue" OnCommand="lbtnSorting_Click" CommandArgument="TotalBalanceDue" runat="server"></asp:LinkButton>
                            <%--<a href="#" onclick="ClientSort('TotalBalanceDue')">Total Balance Due</a>--%>
                        </th>
                    </tr>
                </thead>
                <tbody>
        </HeaderTemplate>
</asp:Repeater>

And the Code Behind :

protected void lbtnSorting_Click(object sender, CommandEventArgs e)
    {
        string s = e.CommandArgument.ToString();
    }
Sign up to request clarification or add additional context in comments.

Comments

2

You cannot simply call an ASP.NET-method from your JavaScript. This is because ASP.NET is purely server-side and JavaScript is client-side.
ASP.NET generates HTML and JavaScript from your .NET code and this happens ONLY during postbacks or Initial loads.
ASP.NET renders a side, provides it and from this Moment on is out of the game until postback.

See ASP.NET-page lifecycle and this post.

Comments

1

To invoke server-side code without reloading the page, use jquery ajax function: http://api.jquery.com/jQuery.ajax/

3 Comments

i have no consult with load page...i just want to call server side function from javascript...
and this is how you can do it
if you have difficulties implementing ajax communication between client and server, you can ask specific questions
0

I had a similar issue got fixed by following code...hope someone will benefit:- I need to call a server side function (button click event functionality) from client side just by Onblur of a Textbox:

asp:TextBox ID="txtNum" runat="server" CssClass="Textbox" Width="170px" MaxLength="8" onblur="javascript:return check2();"/>"

 //JAVASCRIPT - onblur calls button click serverside function
 function check2() {
     document.getElementById("<%=btncheck.ClientID%>").click(); 
 }

asp:Button ID="btncheck" runat="server" Text="Verify" OnClick="check1" />

//CODE BEHIND - On clicking the Button
protected void check1(object sender, EventArgs e)
{
    string str1 = txtBox.Text;
    CheckCCN2(str1);        
}
//Onblur of the Textbox txtNum   
public void CheckCCN2(string strCCNNum)
{
  //all your server side code    
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.