Is it possible that __doPostBack() would ever send a GET request?

孤者浪人 提交于 2019-12-11 01:35:36

问题


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??


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/2456874/is-it-possible-that-dopostback-would-ever-send-a-get-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!