通过函数刷新时关闭弹出窗口

时间:2016-10-13 16:14:13

标签: c# asp.net popup modalpopupextender

我已经完成了所有设置并且功能已经正常工作,一切似乎都很好。只有一个疑问,我不知道它是否可能。我有一个打开modalpopupextender的按钮,在那里,我有一个表单,它有另一个按钮,激活一个下拉列表(我抓住所有信息的那个),点击按钮后,它应该是填写所有表格。 问题是,它关闭了modalpopupextender,虽然功能正在完成,但我不想要的是关闭窗口,我的意思是刷新弹出窗口而不关闭它

这是......

Class.aspx

<asp:Panel ID="panelEmail" Height="680px" Width="800px" runat="server" CssClass="modalPopUp">
    <h2>Contact by Email:</h2>
    <hr />
    <blockquote>
        <legend>Pick the template to use: </legend>
        <asp:dropdownlist id ="ddlTemplate" runat ="server" Height="23px" Width="436px">
              </asp:dropdownlist >  
        <asp:Button ID="Button1" runat="server" Text="Select" OnClick="Template_Changed" />   
        <legend>Email Recipient: </legend>
        <asp:TextBox ID ="emailT" runat="server" Width="356px" Height="24px" Visible="true" Text="prueba@prueba.com"></asp:TextBox>
        <legend>Email Subject: </legend>
        <asp:TextBox ID ="title" runat="server" Width="356px" Height="24px" Visible="true" ></asp:TextBox> 
        <asp:TextBox ID ="txtDetails" runat="server" Width="672px" Height="267px" Visible="true" ></asp:TextBox>
        <ajaxToolkit:HtmlEditorExtender ID="TextBox1_HtmlEditorExtender" runat="server" TargetControlID="txtDetails" 
            EnableSanitization="false" DisplaySourceTab="true" >
        </ajaxToolkit:HtmlEditorExtender><br />      
        <legend>If you want to save the template, name it: (Optional) </legend>
        <asp:TextBox ID ="nameTemplate" runat="server" Width="356px" Height="24px" Visible="true" ></asp:TextBox>
        <br /><br />
        <div align="center">
        <asp:Button ID="Button2" runat="server" Text="Send Mail" OnClick="SendMail"/> 
        <asp:Button ID="Button3" runat="server" Text="Save Template" OnClick="saveTemplate"/>
        <asp:Button ID="btnCancelEmail" runat="server" Text="Cancel"  CausesValidation="false" />
        </div>
    </blockquote>           
</asp:Panel>

<!-- Código añadido por Enrique Bravo -->
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender4" runat="server"
    PopupControlID="panelEmail" 
    TargetControlID="lnkEmail"
    CancelControlID="btnCancelEmail"
    BackgroundCssClass="modalBackGround" 
    DropShadow="true" ></ajaxToolkit:ModalPopupExtender>

                        <tr id="trEmail">
                            <td>
                                <asp:Image ID="Image1" runat="server" ImageUrl ="Images/share.png" width="22px" height="22px" />
                            </td>
                            <td align="left" valign="middle">
                                  <asp:LinkButton ID="lnkEmail" runat="server" Text="Email Contact" ></asp:LinkButton> 
                            </td>
                        </tr>

Class.aspx.cs

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack){
loadlist();
         }
    }

    public void loadList()
    {
        if (!this.IsPostBack)
        {
            try
            {
                BO.Messages template = new BO.Messages();
                ddlTemplate.DataSource = template.GetAll();
                ddlTemplate.DataTextField = "Title";
                ddlTemplate.DataValueField = "Id";
                ddlTemplate.DataBind();
                ddlTemplate.SelectedIndexChanged += Template_Changed;
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }
    }

    /// <summary>
    /// Select the correct Message if there has been one template selected
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Template_Changed(object sender, EventArgs e)
    {

        int countryId = int.Parse(ddlTemplate.SelectedItem.Value);
        if (countryId > 0)
        {
            BO.Messages texto = new BO.Messages();
            txtDetails.Text = texto.GetByID(countryId).Body;
            title.Text = texto.GetByID(countryId).Subject;

        }
    }

1 个答案:

答案 0 :(得分:1)

正如所提供的信息here所说:

  

回发是交互式网页所采取的动作,当整个页面及其内容被发送到服务器处理某些信息时,服务器会将同一页面发回给浏览器。

因此,无论何时单击按钮,页面都会被发送回服务器,更改并发送回客户端,从而导致刷新。

为避免刷新,您可以执行以下两项操作之一:

  1. 使用UpdatePanel控件
  2. 将方法Template_Changed设为[WebMethod]并通过ajax调用它。

    $.ajax({ type: 'POST', url: '<%= ResolveUrl("~/Class.aspx/Template_Changed") %>', data: '{ templateId:' + JSON.stringify(value) + ' }', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (result) { /****FILL FORM HERE ***/}; });