Here is my HTML code snippet:
<a id="PopUp" runat="server" href="#openModal">Open me</a>
// This code opens a pop-up window using HTML
<div id="openModal" runat="server" class="modalDialog">
<div>
<a href="#close" title="Close" class="close">X</a>
<h2 style="text-align:center">Error</h2>
<p style="text-align:center"> Please select the product first!</p>
</div>
</div>
In this code, I set the href link to #openModal in order to open the pop-up window styled with CSS. Now, I want to achieve the same dynamically through C# from the code behind.
I attempted the following code:
if(something..)
{
// do something...
}
else
{
// Open the pop-up message if the condition fails
openModal.Attributes.CssStyle.Add(HtmlTextWriterStyle.Display, "block");
// or
PopUp.Href="#openModal";
}
Unfortunately, none of these methods worked for me. Can someone guide me on how to achieve this functionality from the code behind? Thank you!
P.S. The trigger for this code should be when the user clicks a button inside the listview (normal ASP.NET button)...
Edit: ( Roberth, did you mean like this??):
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="DropDownList1" eventname="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger controlid="Button1" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" runat="server"></asp:DropDownList>
<cc1:ModalPopupExtender runat="server" ID="kontroller" PopupControlID="popUpController" TargetControlID="PopUp">
</cc1:ModalPopupExtender>
<asp:Button ID="PopUp" runat="server" CommandName="AddToCart" CommandArgument='<%# Eval("ProductID")%>' Text="Add to cart" />
</ContentTemplate>
</asp:UpdatePanel>
Code behind:
ModalPopupExtender mpe = e.Item.FindControl("kontroller") as ModalPopupExtender;
mpe.Show();
return;
However, nothing seems to happen with this implementation...