views:

219

answers:

3

I'm having a problem with telerik RadGrid, I want to enable multiple row selection. I also want to go to the server whenever a row is selected or deselected. I created a javascript function to handle the Grid's client side events (OnRowSelected, and OnRowDeSelected). The functions look like this:

 function onOperationRowSelected(sender, eventArgs) {
            __doPostBack("<%=myControl.ClientID %>", "rowSelected:" + eventArgs.get_itemIndexHierarchical());
        }

The other function is very similar, the only difference is that it sends the string "rowDeselcted" instead of "rowSelected".

On Page_Load I check to see if the request is a Post request using "IsPostBack" and if so, I check to see if it's a rowSelected or rowdeselected.

My problem is when I select a first raw on my grid, a Post request happens (which is expected), however, when I select the second row, a GET request is issued, which (obviously) will result in IsPostBack returning false.

What am I missing here?


EDIT: I just checked the Request object and found that the HttpMethod property value is "POST". How come it's an HTTP POST request and IsPostBack returns false??

+2  A: 

The function respects the action of the <form>. Here's what __doPostBack does:

function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}

So it'll do whatever the form is set to do, that's just typically post in asp.net.

So is it possible? Yes, absolutely, why it's occurring in your case I'm not sure.

Nick Craver
+2  A: 

Without seeing the markup that the grid generates, I'm assuming that it uses a link with a javascript-applied click handler to do the postback. I think the most likely culprit, then, is a javascript error which is preventing the handler from firing, which gives you the default behavior of the anchor to which the handler is applied, in this case a GET. Best advice I can give you is to look at it in Firefox/Firebug and see if there are any errors shown in the console.

That said, you might want to build the app so that it works if javascript is disabled and both correct the error and figure out how to respond if you do end up with a GET request.

tvanfosson
please check my edit!
Galilyou
You might want to look at this forum post: http://forums.asp.net/p/1079528/3172367.aspx. Is it possible that you are loading a link that has an empty url when the first event fires?
tvanfosson
+1  A: 

Are you sure the GET request has the right event argument?
I think there is something else that is making the GET request. Probably some AJAX magic by that grid, some resource or AJAX PageMethod call or URL rewriting thing or something like that.

Is the page name default.aspx or something alike? Sometimes in some browser (can't remember details) getting an image or so (can't remember exact situation) makes the browser also hits the "samefolder/" URL, which opens the default page.

Check the request with FireBug and see what it tells.

Mohamed Meligy
Indeed it was a hidden ajax call by the grid, OnRowSelected Fires OnRowDeselcted first that is, when you select a row, the previously selected row fires OnRowDeselected which by default issues a get request.
Galilyou