asp.netAsp.net开发

ASP.NET Customizing Popup Page

2017-06-08  本文已影响34人  LillianSiYin

1. Precondition

2. Steps of A Simple Demo

  1. Create a new asp.net website project.
  2. Add AjaxControlToolkit with Nuget like this:
    AjaxControlToolkit
  3. Check the Web.config file, inside the <pages> tag of the <system.web> tag:
<controls>
      <add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
  1. Create a web form with an HTML <table> with some static values and an OK and Cancel button. Place these controls (not the link button) inside a Panel control.
    And it’s mandatory to register the assembly AJAXControlToolKit.dll. So the following code has to be placed after the page directive of the web form:
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
  1. If the ScriptManager tag is not present in this form, then it should be specified inside the Form tag:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
  1. Design the page like this (Only related to the popup page, using some bootstrap css class):
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Label ID="lblHidden" runat="server" Text=""></asp:Label>
<ajaxToolkit:ModalPopupExtender ID="mdlpopChooseFile" runat="server" TargetControlID="lblHidden" 
    PopupControlID="divPopUp" BackgroundCssClass="ModalPopupBG">
</ajaxToolkit:ModalPopupExtender>
<div id="divPopUp" class="pnlBackGround" style="border-radius:4px;">
      <div class="panel panel-default" runat="server">
        <div class="panel-heading">
            <h3 class="panel-title" style="font-weight: bold; font-size:20px">&nbsp;&nbsp;EDIT APP FILE
            <a href="IOSAppListPage.aspx" class="panel-right" style="margin-top: -0.2em; 
                padding: 0.3em; font-size: 0.9em; font-weight:normal; 
                float: right; color:dimgrey; text-decoration: none;">x</a>
            </h3>
        </div>
        <div class="panel-body">
            <h5>Which file do you want to edit?</h5>
            <asp:RadioButtonList ID="radiobtnlistChooseFile" runat="server">
            <asp:ListItem Value=".plist">&nbsp;&nbsp;.plist file</asp:ListItem>
            <asp:ListItem Value=".ipa">&nbsp;&nbsp;.ipa file</asp:ListItem>
            <asp:ListItem Value=".html">&nbsp;&nbsp;.html file</asp:ListItem>
            </asp:RadioButtonList><br /><br />
            <asp:Button ID="btnContinue" runat="server" Text="Continue" OnClick="btnContinue_Click"  
              CssClass="btn btn-primary" Style="width:150px; margin-left:15px; margin-right:15px; 
              background-color:#737373; color:white; border-radius:4px; border-color:#737373"/>
        </div>
      </div>
</div>
  1. For this pop up page, we add some css like this which name is style.css:
.ModalPopupBG {
    background-color: #666699;
    filter: alpha(opacity=50);
    opacity: 0.7;
}
.pnlBackGround {
    min-width: 200px;
    min-height: 150px;
    background: white;
}
  1. In the <head> tag of this web form, place the following code to access the css file:
<link href="styles/style.css" rel="stylesheet" />
  1. Then from Code behind On Click event of the button Open PopUp :
protected void btnOpenMdlpopChooseFile_Click(object sender, ImageClickEventArgs e){
      mdlpopChooseFile.Show();
}

Then on click of Ok Button :

protected void btnOk_Click(object sender, ImageClickEventArgs e) {
      mdlpopChooseFile.Hide(); 
}

On Cancel click button :

protected void btnCancel_Click(object sender, ImageClickEventArgs e){
      mdlpopChooseFile.Hide();
}

3. Result

Simple pop up page view

4. Conculsion

ASP.NET Ajax control kit is a nice contribution from the ASP.NET community, which is equipped with a lot of good and handy control extenders. This article explored ModalPopupExtender control of ajaxToolkit. There are various scenarios in which modal popup controls can become a handy tool to use in ASP.NET rich clients and also in general purpose web applications.

ref:
  1. ASP.NET AJAX Control Toolkit ModalPopupExtender Control in Action
  2. ASP.NET WebForms Modal Popup window
上一篇下一篇

猜你喜欢

热点阅读