Modal Popup Extender animation in ASP.net - c#

I am currently developing an ASP.net c# application. I have a grid view which has bound link buttons inside. When the link button is pressed I want to display the modal popup using a fade in animation and a fade out animation when a button inside the modal popup is clicked.
I have added the animation extender into the code and set the TargetControlID to the ID of the link button, however, when I try to run the website it displays the error System.InvalidOperationException the TargetControID of ModalPopupExtender is not valid. A control with ID 'sofLink' could not be found. sofLink is the ID of the LinkButton.
Below is the code for the grid view
<asp:GridView ID="tblSoftware" runat="server" Width="100%"
EnableModelValidation="True" AutoGenerateColumns="False"
onselectedindexchanged="tblSoftware_SelectedIndexChanged"
CellPadding="2">
<Columns>
<asp:TemplateField HeaderText="Software Name">
<ItemTemplate>
<asp:LinkButton ID="sofLink" Text='<%# Bind("sof_softwareName") %>'
CommandName="sofID" OnCommand="GetSoftwareModal" CommandArgument='<%# Eval("sof_id") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="sof_platform" HeaderText="Platform" ReadOnly="True" SortExpression="sof_platform" />
</Columns>
<HeaderStyle CssClass="gridHeader" />
<PagerSettings Position="Bottom" />
<PagerStyle HorizontalAlign="Right" VerticalAlign="Middle" CssClass="gridPage" />
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
</asp:GridView>
And below is the code for the ModalPopupExtender
<ajaxToolkit:ModalPopupExtender ID="mpe" runat="server" TargetControlID="sofLink"
PopupControlID="ModalPanel" DropShadow="true" Drag="true" OkControlID="OKButton" />
<asp:Panel ID="ModalPanel" runat="server" Width="500px" style="width: auto; height: auto;" CssClass="modalPopup">
<asp:Label ID="softwareTitle" Font-Bold="true" Font-Size="Medium" runat="server" Width="100%" style="text-align: center;" /><br /><br />
<asp:Literal ID="litSoftware" runat="server"></asp:Literal>
<asp:Button id="OKButton" runat="server" Text="Close" style="position: relative; right: 0px; width: 100px;" />
</asp:Panel>
<asp:ScriptManager ID="asm" runat="server" />
And below is the code for the animation
<ajaxToolkit:AnimationExtender ID="popupAnimation" runat="server"
TargetControlID="sofLink">
<Animations>
<OnClick>
<Parallel AnimationTarget="ModalPanel"
Duration="0.3" Fps="25">
<FadeIn />
</Parallel>
</OnClick>
</Animations>
</ajaxToolkit:AnimationExtender>
Thanks for any help you can provide.

The TargetControlID (as far as I am aware) should be a control in the popup panel itself, not in the grid control. When I use the ModalPopupExtender I usually use an asp:Button with 'display:none' as the TargetControlID. Eg,
<ajaxToolkit:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnPopup"
PopupControlID="ModalPanel" DropShadow="true" Drag="true" OkControlID="OKButton" />
<asp:Panel ID="ModalPanel" runat="server" Width="500px" style="width: auto; height: auto;" CssClass="modalPopup">
<asp:Button id="btnPopup" runat="server" style="display:none" />
In the code-behind you have to control the showing and hiding of the control base on an event, eg, GetSoftwareModal. You will also also to bind what you need if applicable.
Hope that helps.

You could use a hidden button and use it's ID as TargetControlID of the ModalPopupExtender.
<asp:Button id="btnShowPopup" runat="server" style="display:none" />
Then you can call the button's click clientside if you want to show the popup immediately without postback in the follwoing way:
<asp:LinkButton ID="sofLink" runat="server" OnClientClick="javascript:document.getElementById('btnShowPopup').click();return false;">LinkButton</asp:LinkButton>

I tried however my animation doesn't display.
I add databind into LinkButton:
<asp:LinkButton ID="sofLink" runat="server" OnClientClick="javascript:document.getElementById('DetailView1').databind();document.getElementById('btnShowPopup').click();return false;">LinkButton</asp:LinkButton>
I think because of databind of DetailView1, it need get data from database. If DetailView1 doesn't bind, the animation display normal.

Related

hide panel based on grid view row selection in same page on server side

I have below GridView with radio button as column. I want to hide or display panel based on GridView row selection that will be rendering outside of GridView in same page.
Below is my GridView:
<table style="width: 95%; margin-top: 10px;" class="transferCertsTbl">
<tr style="width: 95%">
<td colspan="2">
<asp:GridView ID="gvClearpassCertInfo" runat="server" AutoGenerateColumns="False" GridLines="None"
CellSpacing="1" CellPadding="1"
Width="95%" BorderWidth="0"
AllowSorting="True"
PageSize="30"
OnRowDataBound="gvClearpassCertInfo_RowDataBound"
CssClass="data responsive">
<Columns>
<asp:TemplateField HeaderText="Select" SortExpression="">
<ItemTemplate>
<asp:RadioButton ID="radioChkCert" runat="server" onclick="RadioCheck(this);" /><input type="hidden" id="hdnCertId" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "CertId") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CertificateID" HeaderText="Certificate ID" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="partID" HeaderText="Part Number" HeaderStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="BaseLicense" HeaderText="Base License" Visible="false" />
</Columns>
<EmptyDataRowStyle CssClass="AlternatingRowStyle" />
<HeaderStyle CssClass="HeaderStyle" HorizontalAlign="Center" />
<RowStyle HorizontalAlign="Center" />
<AlternatingRowStyle HorizontalAlign="Center" />
<PagerSettings Visible="False" />
</asp:GridView>
</td>
</tr>
</table>
But I am not sure how to display or hide based on row selection in GridView on server side only.
Could any one please help on this that would be very grateful to me?
You can do the following:
For the radio button tag add autopostback=true and OnCheckedChanged="radioChkCert_CheckedChanged" like this:
<asp:RadioButton ID="radioChkCert" runat="server" onclick="RadioCheck(this);" autopostback="true" OnCheckedChanged="radioChkCert_CheckedChanged"/>
in the codebehind add the function:
protected void radioChkCert_CheckedChanged(object sender, EventArgs e)
{
radiobutton radiobtn = (radiobutton)sender;
string txt = (((Label)radiobtn.Parent.FindControl("l1")).Text); //l1 is the id of a label in the gridview
if ((txt == "CertainCode")) {
Certainpanel.Visible = true;
}
}
Note:
I used the label's text to control which panel to show, in your case choose it depending on which control and it's value.
I converted from vb.net to C# tell me if there is an error

Place RequiredFieldValidator inside a asp:DataList

I have a problem with placing RequiredFieldValidator into a DataList, and some assistance would be greatly appreciated.
Problem description:
When I place the <asp:RequiredFieldValidator>inside the <ItemTemplate> and run the page I get the following error page:
When I place it outside of it, the page works with no error, but obviously it cannot identify witch <asp:TextBox> does not have content in it, before it is posted back. And I would like to make where it is able to tell if a particular text box in the data list does not have text entered.
Here is the markup: (the Image src attribute is not implemented yet)
<asp:DataList ID="imageUploadRoster" runat="server"
DataSourceID="ImageUploadRosterDataSource" RepeatDirection="Horizontal" RepeatColumns="5" HorizontalAlign="Left">
<HeaderTemplate>
<h3>Set Image Names</h3>
</HeaderTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Height="180px" Width="180px" />
<ItemTemplate>
<div class="imageSetNameDiv">
<asp:HiddenField ID="ImageId" runat="server" Value='<%# Eval("ImageId") %>' />
<asp:HiddenField ID="ImageMimeTypeLabel" runat="server" Value='<%# Eval("ImageMimeType") %>' />
<asp:Image ID="ImageThumbnailLabel" runat="server" Src='<%# Eval("ImageThumbnail") %>' Width="120px" Height="120px" />
<br />
<asp:RequiredFieldValidator ID="imageNameRequired" runat="server"
ControlToValidate="ImageName" ErrorMessage="RequiredFieldValidator"
ValidationGroup="imageUploadValid">
</asp:RequiredFieldValidator>
<asp:TextBox ID="ImageName" runat="server" Text='<%# Eval("ImageName") %>' />
<br />
<hr />
<asp:Button ID="removeImage" runat="server" Text="Remove" CommandName="delete" CommandArgument='<%# Eval("ImageId") %>' />
</div>
</ItemTemplate>
</asp:DataList>
Thank you in advance for any assistance.
Peter
This error happens when ASP.NET encounters two controls with the same ID on the page. I guess for some reason in your case validators for each item get the same ID. Setting the following property:
ClientIDMode="Predictable"
for validator should fix it. This mode makes sure control in databound context gets correct ID.

Modal Popup control not firing orginal button click event

Maybe I am not understanding how this works completely but what I have is a gridview custom template with an imagebutton and a modalpopup. Below my page I have my popup panel which is hidden. When I click my image button the panel displays then I click the "btnModalCancelAll" and it starts to step through my method which sets a page variable from 0 to 1 but then the problem comes in it does not continue to the original gridview image click event not sure why. Below is my template field and the popup panel.
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButtonCancelResv" runat="server" Width="20" Height="20px" ImageUrl="~/Images/Delete.png" OnClick="ImageButtonCancelResv_Click" />
<asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="ImageButtonCancelResv" PopupControlID="pnlModalPanel" CancelControlID="btnModalCancel"></asp:ModalPopupExtender>
<br />
<asp:Label ID="Label1" runat="server" Text="Cancel"></asp:Label>
</ItemTemplate>
<asp:Panel ID="pnlModalPanel" CssClass="modalBackground" runat="server" Style="display:none">
<asp:UpdatePanel runat="server" ID="updatePanelPopUp">
<ContentTemplate>
<div id="modalWrap">
<asp:Label ID="lblAreyousure" runat="server" Text="Are you sure you want to do that?"></asp:Label>
<div id="divhr1" class="horizontalRule" runat="server"></div>
<div id="divCancelSummaryAll">
<asp:Label ID="lblEntireFamily" runat="server" Text="Cancel all family reservations from this event date."></asp:Label><br />
<asp:Label ID="lblSummaryDeleteAll" runat="server" Text=""></asp:Label><br />
<asp:Button ID="btnModalDeleteAll" runat="server" CssClass="modalButton" Text="Cancel all Family" OnClick="btnModalDeleteAll_Click" />
</div>
<div id="divCancelSummaryOne">
<asp:Label ID="Label2" runat="server" Text="Cancel selected child reservation from this event date."></asp:Label><br />
<asp:Label ID="lblSummaryDeleteOne" runat="server" Text=""></asp:Label><br />
<asp:Button ID="btnModalDeleteOne" runat="server" CssClass="modalButton" Text="Cancel this Child" OnClick="btnModalDeleteOne_Click" />
</div>
<br />
<asp:Button ID="btnModalCancel" runat="server" Text="Cancel" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
I suggest you create another button and use it as the TargetControlID for the modal popup.
you can hide this button by setting its display to 'none'. This will only be a dummy button so that your code compiles.
Now when you click the button "ImageButtonCancelResv" it will run your code which is in the method OnClick="ImageButtonCancelResv_Click"
and at the end of this method you can add a command to show the popup:
mpe.Show();
Example Code:
protected void ImageButtonCancelResv_Click(object sender, EventArgs e)
{
//Do something here when button is clicked
mpe.Show();
}
And then
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButtonCancelResv" runat="server" Width="20" Height="20px" ImageUrl="~/Images/Delete.png" OnClick="ImageButtonCancelResv_Click" />
<div style="display: none">
<asp:Button ID="btnModalStatusHidden" runat="server" />
</div>
<asp:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnModalStatusHidden" PopupControlID="pnlModalPanel" CancelControlID="btnModalCancel"></asp:ModalPopupExtender>
<br />
<asp:Label ID="Label1" runat="server" Text="Cancel"></asp:Label>
</ItemTemplate>

Can't seem to get RequiredFieldValidator in nested user control to fire

I have a user control (form) inside a user control (grid) with a Validator in the form. A snippet from the code is below
<asp:tablerow>
<asp:tablecell HorizontalAlign="center" columnspan="2" >
<asp:ValidationSummary runat="server" id="ValidationSummary1" />
</asp:tablecell>
</asp:tablerow>
<asp:tablerow>
<asp:tablecell HorizontalAlign="left" style="padding-left:250px;" >
<asp:label ID="Label1" runat="server" Text="Foo:" AssociatedControlId="txtFoo" />
</asp:tablecell>
<asp:tablecell HorizontalAlign="left" style="padding-right:200px;" >
<asp:textbox runat="server" id="txtFoo" Text="" />
&nbsp
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ErrorMessage="Foo is a Required Field"
Text="*"
ControlToValidate="txtFoo" />
</asp:tablecell>
</asp:tablerow>
This code is identical to code in another user control where the parent is not a user control and that page works fine, but on this page the Validator doesn't fire and the Foo_ItemCommand method fires instead. I tried searching Google and StackOverFlow but haven't been able to find anything that helps.
Thanks for any assistance you might have.
Dan
try to use ValidationGroup for validation controls and submit control.

GridView, Child GridView, extra column won't disappear?

I'm building a GridView control which encapsulates a child gridview. The child gridview holds a div tag which is displayed when the user selects a row in the parent gridview. However, even though the contents is hidden i.e. the div tag, an extra column is added - how do I get rid of the extra column. In the tutorial it states that by adding a </td></td> and starting a new row <tr> this should happen but it does (I also noticed that the author turned off gridlines so my assumption is that he in fact has this problem also). Here is the gridview, oh and I set the visible state of the itemtemplate to 'true' but then the javascript could (not) find it.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" DataKeyNames="PublicationID"
DataSourceID="ObjectDataSource1" Width="467px" OnRowDataBound="GridView1_RowDataBound"
Font-Names="Verdana" Font-Size="Small">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="PublicationSelector" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:TemplateField HeaderText="Owners">
<ItemTemplate>
<asp:Label ID="Owners" runat="server"></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:TemplateField>
<ItemTemplate >
</td></tr>
<tr>
<td colspan="7">
<div id="<%# Eval("PublicationID") %>" style="display: none; position: relative">
<asp:GridView ID="GridView2_ABPubs" runat="server" AutoGenerateColumns="false" Width="100%"
Font-Names="Verdana" Font-Size="small">
<Columns>
<asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Apart from the extra column in the master gridview it works fine.
Just for completeness, here is a to the original article (for some reason it didn't like my <a href> tag so it's copy and paste).
To get rid of the extra column, just set its css style to display: none. You can do this by applying a CssClass to the TemplateField containing the nested grid:
<asp:TemplateField HeaderStyle-CssClass="hidden-column" ItemStyle-CssClass="hidden-column" FooterStyle-CssClass="hidden-column">
Here is the definition of the CssClass I used:
<style type="text/css">
.hidden-column {
display: none;
}
</style>
Note: the markup will still be in the html but at least it won't be visible.
Tested under IE 8.0, Google Chrome 2.0 and Opera 10.0
Update: To eliminate the double border, just put the id and the style on the <tr> instead of the <div>:
<tr id="<%# Eval("PublicationID") %>" style="display: none; position: relative">
<td colspan="7">
<div>
...
... and change the display in the javascript from block to table-row:
div.style.display = "table-row"; // not a div anymore!!
Looks like you have unbalanced tags in your <ItemTemplate>:
<ItemTemplate >
</td></tr> <<---- These look unbalanced
<tr>
<td colspan="7">
<div id="<%# Eval("PublicationID") %>" style="display: none; position: relative">
<asp:GridView ID="GridView2_ABPubs" runat="server" AutoGenerateColumns="false" Width="100%"
Font-Names="Verdana" Font-Size="small">
<Columns>
<asp:BoundField DataField="NameAbbrev" HeaderText="Publication Name" SortExpression="NameAbbrev" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
I don't see an opening tag for these tr, td tags:
...
<ItemTemplate >
</td></tr>
...
Just checked and the author of the article seems to have the same issue in the generated source of the page.

Categories