문제

It's a bit of a hack, but I'm forcing a postback on the close event of a jquery dialog.

close: function (event, ui) {
    __doPostBack('<%=btnChange.UniqueID %>', 'refreshMe');
}

It works as it should and it raises the click event on the server side (with a minor annoyance of having to turn off the EnableEventValidation since I'm trying to pass in 'refreshMe').

What I want is to be able to see the 2nd argument ('refreshMe') during the click event so I can know that the postback was caused by the jquery dialog close event. So maybe something like the following is more-or-less what I'm hoping for (but it doesn't work, obviously).

protected void btnChange_Click(object sender, EventArgs e) {
    if (e == "refreshMe")
    {
        // do whatever
    }
    else
    {
        // do whatever
    }
}

Is there some way that I can go about doing this, or am I way off base?

Thanks for the help.

EDIT In order to get this scenario working I had to: 1) set EnableEventValidation to false (if its true then ASP.NET will throw an error and basically tell you that its unable to validate the request) 2) I tried setting the value of the hidden __EVENTARGUMENT using jquery, but for whatever reason the value 'refreshMe' never was sent to the server in the argument. What I ended up doing was putting 'refreshMe' in the 2nd argument of the _doPostBack, and then it showed up in the Request["_EVENTARGUMENT"] on the server side.

도움이 되었습니까?

해결책

ASP.Net stores a hidden field on the page which should contain your "refreshMe" value on postback.

<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

You should be able to get the __EVENTARGUMENT value in Page_Load:

protected void Page_Load(object sender, EventArgs e) {
   if(Page.IsPostBack) {
      string eventArg = Request("__EVENTARGUMENT");
      if (eventArg == "refreshMe") {
         // ...
      }
   }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top