简体   繁体   English

window.parent.location.href无法与asp.net中的ajaxcontroltoolkit一起使用

[英]window.parent.location.href not working with ajaxcontroltoolkit in asp.net

I am using iframe to open new .aspx page from parent page. 我正在使用iframe从父页面打开新的.aspx页面。 child page is using ajaxcontroltoolkit(ajax CalendarExtender). 子页面正在使用ajaxcontroltoolkit(ajax CalendarExtender)。 Now on form submit, I want to close iframe and return to parent page. 现在在表单提交中,我想关闭iframe并返回到父页面。 For that I am using following code. 为此,我正在使用以下代码。

ClientScript.RegisterStartupScript(this.GetType(), "scriptid", window.parent.location.href='ViewVendors.aspx'", true);

This works file if I remove ajax control from child page but does not work with ajax control. 如果我从子页面中删除了ajax控件,但它不适用于ajax控件,则此文件有效。 I want to use calenderExtender and iframe both. 我想同时使用calenderExtender和iframe。 How can I use it and what is the problem for such so called abnormal behavior. 我如何使用它以及所谓的异常行为有什么问题?

This is the code for my submit button event handler. 这是我的提交按钮事件处理程序的代码。

protected void btnUpdate_Click(object sender, EventArgs e)
{
    try
    {
        objVendor.VendorID = Convert.ToInt64(Request.QueryString["Id"]);
        objVendor.Name = txtName.Text;
        objVendor.BillingAddress = txtBillingAddress.Text;
        objVendor.ShippingAddress = txtShippingAddress.Text;
        objVendor.ContactPersonName = txtContactPerson.Text;
        objVendor.ContactNumber = txtContactNumber.Text;
        objVendor.EmailID = txtEmailID.Text;
        objVendor.VendorSinceDate = Convert.ToDateTime(txtVendorDate.Text);
        objVendor.IsActive = Convert.ToBoolean(rdblStatus.SelectedValue);
        objVendor.Logo = FileUpload();
        int intResult = objVendor.UpdateVendor();
        if (intResult > 0)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "window.parent.location.href='ViewVendors.aspx'", "scriptid", true);
            //ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='ViewVendors.aspx'", true);
        }
    }
    catch (Exception ex)
    {
        lblMessage.Text = ex.Message;
        lblMessage.CssClass = "ERROR";
    }
}

//Edit Now my code works fine as long as I am not adding calender extender to the child page. //现在,只要不向子页面添加日历扩展器,我的代码就可以正常工作。 When I add calender extender in child page it shows error "The Controls collection cannot be modified because the control contains code blocks (ie <% ... %>)". 当我在子页面中添加压延扩展器时,它显示错误“无法修改控件集合,因为控件包含代码块(即<%...%>)”。 If I remove calender extender, again it works well. 如果我删除了压延机补充剂,它再次可以正常工作。 By doing some googling, I found that <% %> in Javascript tag is creating problem. 通过进行一些谷歌搜索,我发现Javascript标记中的<%%>造成了问题。 How can I solve it and why calender control is creating problem in such cases? 我该如何解决?为什么在这种情况下压延机控制会造成问题?

Here is the code for my script. 这是我的脚本的代码。

<script type="text/javascript">
    function uploadStarted() {
        $get("imgDisplay").style.display = "none";
    }
    function uploadComplete(sender, args) {
        var imgDisplay = $get("imgDisplay");
        //  var imgPhoto = $get("#imgPhoto");
        var imgPhoto = document.getElementById('<%=imgPhoto.ClientID %>');
        imgDisplay.src = "images/loader.gif";
        imgPhoto.style.display = "none";
        imgDisplay.style.cssText = "";
        var img = new Image();
        img.onload = function () {
            imgDisplay.style.cssText = "height:100px;width:100px";
            imgDisplay.src = img.src;
        };
        img.src = "<%=ResolveUrl(UploadFolderPath) %>" + args.get_fileName();

    }
</script>

You need to register your JavaScript using the ScriptManager instance on your page - which you should already have if you're using AJAX. 您需要使用页面上的ScriptManager实例来注册JavaScript-如果使用AJAX,则应该已经具有该实例。 It has its own RegisterStartupScript method that you can use. 它具有您可以使用的自己的RegisterStartupScript方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM