ModalPopup nested in GridView

September 24, 2008 18:47 by John M


This may be old news for some of you out there but for those of you who are just starting to use the AjaxControlToolkit I wanted to show how you can nest the ModalPopup inside a GridView.  This technique has worked for the most part.  However, I will caution if you show a lot of records within the gridview  it could slow up performance on rendering the page.  Keep in mind this technique below is adding the ModalPopup to each row within the gridview. 

First you need the following style within the page your CSS sheet

.modalBackground
{
    background-color:#f5f5f5;
    filter:alpha(opacity=80);
    opacity:0.7;
}


Second you will notice we have the AjaxControlToolkit registered on the aspx page, along with a ScriptManager

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

Third, you will see the GridView with one TemplateField that has a LinkButton, Panel, Button and the ModalPopupExtender.

The LinkButton is set as the TargetControlID
The Panel is set as the PopupControlID
The Button is set as the OkControlID

<asp:GridView ID="gvSchedule" runat="server" AutoGenerateColumns="false" ShowHeader="false" GridLines="None" HorizontalAlign="Center">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <table cellpadding="5" cellspacing="0">
                        <tr>
                            <td>
                                <asp:LinkButton ID="lnkBtnViewDetails" runat="server" Text="View" />
                                <asp:Panel runat="server" ID="pnlDetails" style="display: none; width: 500px; border: solid 1px black; overflow: scroll; height: 400px; background-color: White;">
                                     <asp:Literal ID="Literal1" runat="server" Text='<%# (string)Eval("strDetails") %>'></asp:Literal>                                           
                                </asp:Panel>
                                <ajaxToolkit:ModalPopupExtender ID="modalPopUp1" runat="server"
                                    TargetControlID="lnkBtnViewDetails"
                                    PopupControlID="pnlDetails"
                                    BackgroundCssClass="modalBackground"
                                    DropShadow="false"
                                    OkControlID="btnCloseDetails" />
                            </td>
                        </tr>
   <tr>
                            <td style="text-align: center;">
                                 <asp:Button ID="btnCloseDetails" runat="server" Text="Close Details" />
                            </td>
                        </tr>
                    </table>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <AlternatingRowStyle CssClass="gridAltRowStyle" />
 </asp:GridView>

This is pretty much all you need to utilize the ModalPopup nested within a GridView. 

Note: I handled the GridView binding in the code behind, or you can handle it with a SqlDataSource.

Hope this has helped on how you can utilize the ModalPopup inside a gridview.

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

ReOrderList Example AJAX.NET Toolkit

May 5, 2008 11:05 by John M
Again I wanted to use an AJAX Toolkit item and the example Microsoft provided fell a bit short.  Even the example that came with the AJAXToolkit Web Pages still wasn't fully developed. They left out on how to properly edit and update an item in the ReOrderList.  In addition they used an ObjectDataSource and I don't use those very often.

I wanted to provide a full example of the ReOrderList that shows how to read, add, update, and delete items from the ReOrder list using a SQLDataSource instead of the ObjectDataSource Microsoft Provided.  Please ignore the actually looks of this example as I didn't spend any time styling it with CSS.  This just provides the functionality.  

First I created a test table in my local SQL Database called TestTable1.  The columns included are the following:

 - intID (primary with identity enabled)
 - strName
 - strLink
 - intOrder (for order of list items)

Next I coded up the ReOrder List page.  I didn't use any code behind so I'm just pasting what the markup aspx page looks like.

######################################################################


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AJAXOrderList.aspx.cs" Inherits="AJAXOrderList" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>OrderedList AJAX</title>
    
    <style type="text/css">
        .ajaxOrderedList li
        {
            list-style:none;
        }
    </style>
    
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" />        
        <asp:UpdatePanel ID="up1" runat="server">
            <ContentTemplate>
                <div class="ajaxOrderedList">
                  <ajaxToolkit:ReorderList ID="ReorderList1" runat="server"
                    AllowReorder="True"
                    PostBackOnReorder="False"
                    SortOrderField="intOrder"
                    DataKeyField="intID"
                    DataSourceID="sqlDSItems"
                    ItemInsertLocation="End">
                        <ItemTemplate>
                            &nbsp;
                            <asp:HyperLink ID="HyperLink1" runat="server" Text='<% #Eval("strName") %>' NavigateUrl='<%# Eval("strLink") %>' />
                            <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
                            <asp:LinkButton ID="LinkButton3" runat="server" CommandName="Delete" Text="Delete" />
                        </ItemTemplate>
                        <DragHandleTemplate>
                            <div style="height: 20px; width: 20px; border: solid 1px black; background-color: Red; cursor: pointer;">
                                &nbsp;
                            </div>
                        </DragHandleTemplate>
                        <ReorderTemplate>
                            <div style="width: 300px; height: 20px; border: dotted 2px black;">
                                &nbsp;
                            </div>
                        </ReorderTemplate>
                        <InsertItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label><asp:TextBox ID="txtName" runat="server" Text='<%# Bind("strName") %>'></asp:TextBox><br />
                            <asp:Label ID="Label2" runat="server" Text="Link"></asp:Label><asp:TextBox ID="txtLink" runat="server" Text='<%# Bind("strLink") %>'></asp:TextBox><br />
                            <asp:Button ID="btnInsert" runat="server" Text="Add Link" CommandName="Insert" />
                        </InsertItemTemplate>
                        <EditItemTemplate>
                                <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("strName") %>'/>
                                <asp:TextBox ID="txtLink" runat="server" Text='<%# Bind("strLink") %>' />
                                <asp:TextBox ID="txtOrder" runat="server" Text='<%# Bind("intOrder") %>' />
                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" Text="Update" />
                                <asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" />                      
                        </EditItemTemplate>
                    </ajaxToolkit:ReorderList>
                </div>
           </ContentTemplate>
        </asp:UpdatePanel>
        
        <asp:SqlDataSource ID="sqlDSItems" runat="server" ConnectionString="<%$ ConnectionStrings:sqlLocal %>"
            SelectCommand="SELECT [intID], [strName], [strLink], [intOrder] FROM [TestTable1] ORDER BY [intOrder]"
            DeleteCommand="DELETE FROM [TestTable1] WHERE [intID] = @intID"
            InsertCommand="INSERT INTO [TestTable1] ([strName], [strLink], [intOrder]) VALUES (@strName, @strLink, @intOrder)"
            UpdateCommand="UPDATE [TestTable1] SET [strName] = @strName, [strLink] = @strLink, [intOrder] = @intOrder WHERE [intID] = @intID">
            <DeleteParameters>
                <asp:Parameter Name="intID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="strName" Type="String" />
                <asp:Parameter Name="strLink" Type="String" />
                <asp:Parameter Name="intOrder" Type="Int32" />
                <asp:Parameter Name="intID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="strName" Type="String" />
                <asp:Parameter Name="strLink" Type="String" />
                <asp:Parameter Name="intOrder" Type="Int32" />
            </InsertParameters>
        </asp:SqlDataSource>
        
    </form>
</body>
</html>

#####################################################

The one item I was wondering about the most was how to actually wire up the Edit, Update, Delete, and Cancel commands to the list. Since I was using a SqlDataSource this actually was very easy. You just need to add the attribute CommandName="" to a LinkButton or Button. For example if I want to activate the EditItemTemplate you'll notice the link button in the ItemTemplate with the attribute CommandName="Edit".

Then you'll notice in the EditItemTemplate to properly edit the item, for Text attribute is '<%# Bind("yourColumn") %>'. This will handle editing back to the database on its own.  You'll also notice the same method for the Text attribute for the TextBoxes in the InsertItemTemplate.

Well again I'm showing this because the example from Microsoft left out the Edit, Update and Delete portions...and didn't use a SqlDataSource that the ReOrder list could bind too.

As always any problem with the code let me know so I can update this post, but I was just using this.

Currently rated 4.0 by 9 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Create a Blind Down effect with AJAX.NET

January 12, 2008 18:36 by John M

I was expirementing with a new website design for our company and I wanted to include some type of animation effect on the home page.  I started off with scriptaculous and found out it was a bit difficult to get going using master pages.  This was because of how the order of the content was getting loaded.  So instead I tried using the Animation Extender in the AJAX toolkit...which I don't use too often.  The goal was to mimic the Blind Down Effect in scriptaculous.  I got pretty close, but not exactly like it would be using scriptaculous.  I had it working in IE, but Firefox processed the DIV's differently, so I came up with another solution.  Basically, I use the following concept:

Start the DIV at height 0px
Resize the DIV to height 200px (this could be whatever works for you)
Fade In the DIV

Below is the code that I used to accomplish this:

<div id="newsHolder" runat="server" class="newsHolder">
     <div id="newsContent" runat="server" style="display:none; margin: 10px 10px 10px 10px">
  
              whatever content you want in here. 
              
     </div>
</div>

<ajaxToolKit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="newsHolder">
        <Animations>
            <OnLoad>
                <Sequence>
                    <Resize Duration="1.0" Height="200" Unit="px" />
                    <StyleAction AnimationTarget="newsContent" Attribute="display" Value="block"></StyleAction>
                    <FadeIn AnimationTarget="newsContent" Duration="1.0"></FadeIn>
                </Sequence>
            </OnLoad>
        </Animations>
</ajaxToolKit:AnimationExtender>


NOTE: the "newsHolder" class consists of the following:

.newsHolder
{
 height: 0px; 
 border: groove 2px silver;
 width: 95%;
 margin-left: 10px;
 margin-right: 10px;
}


If anyone can find a Blind Effect similiar to scriptaculous using the AJAX.NET framework that works proper in both IE and Firefox please response to this post.  I would be interested in knowing how this is accomplished.

 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Animation Extender Example ASP.NET AJAX

October 12, 2007 16:13 by John M

I found myself struggling on how to use the ASP.NET AJAX Control Toolkit Animation Extender.  I wanted to use a simple example on a website that was basically the example they give on the Toolkit website.  I wanted the user to click a link and it would “fly-out” a window to show more information.  I tried to follow the example online however, I found myself missing an important part to it…the CSS aspect of it.  I wanted to write a quick example of how to do this without you trying to read Microsoft’s source code and example online.

Step 1:  The following styles will need to be used in order for this to work.  I would recommend placing the classes into a stylesheet.

.flyOutDiv
{
     display: none;
     position: absolute;
     width: 400px;
     z-index: 3;
     opacity: 0;
     filter:(progid:DXImageTransform.Microsoft.Alpha(opacity=0));
     font-size: 14px;
     border: solid 1px #CCCCCC;
     background-color: #FFFFFF;
     padding: 5px;
}

.flyOutDivCloseX
{
 background-color: #666666;
 color: #FFFFFF;
 text-align: center;
 font-weight: bold;
 text-decoration: none;
 border: outset thin #FFFFFF;
 padding: 5px; 
}

Step 2:  Place the DIV on your web page and the link button that we will use for our target control ID to activate the animation.  You will notice the OnClientClick=”return false;” this is so the link button does not post back.

<asp:LinkButton ID="lnkBtnColHelp" runat="server" Text="Click Here" OnClientClick="return false;" />

<div id="moveMe" class="flyOutDiv">
  <div style="float:right;">
 <asp:LinkButton ID="lnkBtnCloseColHelp" runat="server" Text="X" OnClientClick="return false;" CssClass="flyOutDivCloseX" />
  </div>
<br />
     <p>
        some content here for whatever text
     </p>                         
</div>

Step 3:  Add the AnimationExtender to the web page

<ajaxToolKit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="lnkBtnColHelp">
            <Animations>
                <OnClick>
                    <Sequence>
                        <EnableAction Enabled="false"></EnableAction>
 
                        <StyleAction AnimationTarget="moveMe" Attribute="display" Value="block"/>
                        <Parallel AnimationTarget="moveMe" Duration=".5" Fps="30">
                            <Move Horizontal="-350" Vertical="50"></Move>
                            <FadeIn Duration=".5"/>
                        </Parallel>
                        <Parallel AnimationTarget="moveMe" Duration=".5">
                             <Color PropertyKey="color" StartValue="#666666" EndValue="#FF0000" />
                            <Color PropertyKey="borderColor" StartValue="#666666" EndValue="#FF0000" />
                        </Parallel>
                    </Sequence>
                </OnClick>
            </Animations>
       
        </ajaxToolKit:AnimationExtender>
       
        <ajaxToolKit:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="lnkBtnCloseColHelp">
       
            <Animations>
                <OnClick>
                    <Sequence AnimationTarget="moveMe">
                        <Parallel AnimationTarget="moveMe" Duration=".7" Fps="20">
                            <Move Horizontal="350" Vertical="-50"></Move>
                            <Scale ScaleFactor="0.05" FontUnit="px" />
                            <Color PropertyKey="color" StartValue="#FF0000" EndValue="#666666" />
                            <Color PropertyKey="borderColor" StartValue="#FF0000" EndValue="#666666" />
                            <FadeOut />
                        </Parallel>
                        <StyleAction Attribute="display" Value="none"/>
                        <StyleAction Attribute="height" Value=""/>
                        <StyleAction Attribute="width" Value="400px"/>
                        <StyleAction Attribute="fontSize" Value="14px"/>
                        <EnableAction AnimationTarget="lnkBtnColHelp" Enabled="true" />
                    </Sequence>
                </OnClick>
            </Animations>
       
  </ajaxToolKit:AnimationExtender>


You'll notice in step 3 there are 2 animation extenders.  One is to show and move the DIV and the second is to close, move and hide the DIV.  The StyleAction tag in the second extender are very important because this is what sets the DIV back to the default view as if you just loaded the web page again.

I hope this has made it easier to use the animation extender.  The documentation online as to what the tags mean are very useful at:

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/AnimationReference.aspx

If anyone finds faults or problems in the code feel free to comment.


Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5