views:

27

answers:

1

I want to filter a grid at server side based on the value typed in a text box. And the filter should happen as the user types in text box. Since there is no server side event like keypress on a textbox, I decided to do use the client side onkeypress event and call a server side code using PageMethod. But then ran out with the limitation of PageMethod being static and I can’t access grid from server side code.

< form id="Form1" runat="server">

< asp:ScriptManager ID="ScriptManager" runat="server" EnablePageMethods="true" />
        <input type="text" id="txtFilterLabName" onkeypress ="txtFilterLabName_Keypress()"/>
</form>

<script type="text/javascript">
    function txtFilterLabName_Keypress() {
        // Call a server method.
        PageMethods.txtFilterLabName_Keypress();
    }
</script>

[WebMethod]

public static void txtFilterLabName_Keypress()

{ // Code to filter the grid. }

Is there way to do this?

A: 

You are correct that you cannot access the grid during a page method. A page method is just a web service call and knows nothing about the page the user is on.

To do this you will need to update the grid on the client after making the page method call. I don't believe the standard grid control supports this so you will either need to write your own code to do this or use a third party control.

If you are just displaying data in the grid and not supporing sorting and filtering it may be easy to just update the underlying table via javascript.

Daniel