Request.Form["__EVENTTARGET"] is null while __doPostBack() on close a window in clientside

3 posts, 1 answers
  1. Abhi
    Abhi avatar
    15 posts
    Member since:
    Sep 2012

    Posted 05 Sep 2012 Link to this post

    Hello,
    I have a MDI web form and dynamically creating new radwindows inside that MDI form. I want to some operations on close (X) of that window. For that i have added RadWindow1.OnClientClose = "OnClientCloseClick"; . In OnClientCloseClick event, i have called __doPostBack() in order to implement my logic. On closing window, postback is working. But when i am checking  Request.Form["__EVENTTARGET"] , it's value becomes null. When i am doing the same in a normal aspx page(no windowmanager here), it is showing some value.
                 In MDI form  i have added new window dynamically.
        protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    RadWindow RadWindow1 = new RadWindow();
                    RadWindow1.ID = "RadWindow1";
                    RadWindow1.VisibleOnPageLoad = true;
                    RadWindow1.OnClientClose = "OnClientCloseClick";
                    RadWindow1.NavigateUrl = String.Format("Default.aspx?ID=" + Request.QueryString["ID"]);
                    RadWindowManager1.Windows.Add(RadWindow1);
    }
    }
    JS
     function OnClientCloseClick(sender, args) {
                       __doPostBack('SaveSettingOnClose', 'OnClose');
                       }
    function __doPostBack(eventTarget, eventArgument) {
               document.Form1.__EVENTTARGET.value = eventTarget;
               document.Form1.__EVENTARGUMENT.value = eventArgument;
               document.Form1.submit();
            }
    HTML
    <input type="hidden" name="__EVENTTARGET" value="">
        <input type="hidden" name="__EVENTARGUMENT" value="">

    ---------------
    In Default.aspx (new window created)
    in page load
     if (Request.Form["__EVENTTARGET"] == "SaveSettingOnClose")
                {

                    SaveSettingOnClose();

                }
    Here Request.Form["__EVENTTARGET"] becomes null. so control is not going inside the if block.

    Please provide me solution to solve this issue.

    Thanks
    Abhi
  2. Answer
    rdmptn
    rdmptn avatar
    72 posts
    Member since:
    Aug 2011

    Posted 06 Sep 2012 Link to this post

    OnClientCloseClick is in the context of the parent page and the postback happens in the parent page. This means that the page you load inside the RadWindow will not be posted back. If your RadWindow is viisible on page load with the main page then the content page will be loaded anew and __EventTarget will be empty, of course.

    It seems you need to initiate the postback in the content page, so you need the approach from this article: http://www.telerik.com/help/aspnet-ajax/window-programming-calling-functions.html.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Abhi
    Abhi avatar
    15 posts
    Member since:
    Sep 2012

    Posted 06 Sep 2012 Link to this post

    Hi rdmptn,

    thank you for your reply. Now it is working fine.

    In MDI.aspx

    function OnClientCloseClick(sender, args) {
                    var oWnd = GetRadWindowManager().getWindowByName("RadWindow1");
                    oWnd.get_contentFrame().contentWindow.SaveSettingOnClose();
                }
    if (!Page.IsPostBack)
                {
                    RadWindow RadWindow1 = new RadWindow();
                    RadWindow1.ID = "RadWindow1";
                    RadWindow1.VisibleOnPageLoad = true;
                    RadWindow1.OnClientClose = "OnClientCloseClick";
                    RadWindow1.NavigateUrl = String.Format("Default.aspx?ID=" + Request.QueryString["ID"]);
                     RadWindowManager1.Windows.Add(RadWindow1);
    }

    In default.aspx

    function SaveSettingOnClose() {
                __doPostBack('SaveSettingOnClose', 'OnClose');
            }

    Thanks
    Abhi
Back to Top