Ajax popup causes screen to re-load using ASP.NET - asp.net

I am using the code from How to create a stunning and smooth popup using jQuery. When I click the button to activate the Ajax popup, it does appear, but the page is reloading on the button click.
How do I get around this?

Hard to say without seeing your code, but whatever link/button you are using to launch the dialog, make sure it is returning false from its click event handler (or submit event handler on a form)

Is your modal wired up to an ASP.NET button? If so, this will be set to postback on a click. Perhaps wire the modal to a regular HTML button instead?

Most likely your button is a post back button. You might want to change that configuration so that it does not automatically post back.

Since I'm using an ASP.NET button control, it wanted to post back, so I created an update panel with the AsyncPostBackTrigger ControlID=[my button id].
So the code to make it all work (with loading the jQuery library) is as follows:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="button">
<asp:Button ID="Save1" runat="server" Text="Button" onclick="Save1_Click" />
</div>
<asp:UpdatePanel ID="up1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Save1" />
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
<div id="popupContact">
<a id="popupContactClose">x</a>
<h1>Title of our cool popup, yay!</h1>
<p id="contactArea">
Here we have a simple but interesting sample of our new stuning and smooth popup. As you can see jQuery and CSS does it easy...
<br/><br/>
We can use it for popup-forms and more... just experiment!
<br/><br/>
Press ESCAPE, Click on X (right-top) or Click Out from the popup to close the popup!
<br/><br/>
</p>
</div>
<div id="backgroundPopup"></div>
</div>
</form>

Related

What happens when an update panel doesn't have any triggers?

I have the markup below, there is no triggers section and no setting of the triggers in the code behind. When I click on the checkbox, the page does update and show the hidden div (server side code sets visible), but page loading spinner in the page tab doesn't spin in chrome. If I remove the update and template tags, the page seems to act the same except that the page loading spinner spins.
What is actually happening? Is the page being reloaded or not? If the update panel is loading the page, why is it doing so without a defined AsyncPostBackTrigger?
<asp:UpdatePanel runat="server" ID="pnlMain">
<ContentTemplate>
<div class="control-group">
Hide Div
<div class="controls">
<asp:CheckBox ID="chkbx" CssClass="Input" runat="server" AutoPostBack="true" />
</div>
</div>
<div id="divToHide" runat="server">
stuff to hide when div is clicked
</div>
<div class="form-actions">
<asp:LinkButton ID="btnSubmit" runat="server" Text="Submit" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
Page is loaded in both cases. With Update Panel only Partial Page(Content inside the Content Template is updated) whereas in normal case entire page is re-rendered.

ASP UpdateProgress control on async page load

I have an async page load that fetches data from an API and binds it to a repeater inside an update panel, separate to local search results.
There is a script manager in the master page.
<div class="searchResultContainer" runat="server" id="divApiResults">
<div class="searchResult">
<asp:UpdatePanel ID="udpApiResults" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:UpdateProgress ID="updateProgress" DisplayAfter="1000" runat="server">
<ProgressTemplate>
<div id="lblLoadingApi" runat="server">
Loading...
</div>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:Label runat="server" CssClass="label searchResultLabel" Text="EXTERNAL SEARCH RESULTS" />
<asp:Repeater ID="rptApiResults" runat="server">
<!-- template in here -->
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
However, the update progress control is never shown on page load or when the repeater is sorted or the page changes. How do I get it to show "loading" until all data is loaded in the repeater?
I was doing things wrong. The update progress modal will never appear on an asynchronous page load, due to it being already loaded before the page has rendered. As it was posting back when it was paging and sorting that's when the UpdateProgress appeared.
My solution was load it asynchronously after the page load (as it's in an update panel it doesn't affect the rest of the page), by using a piece of jQuery to click a "trigger" button on $(document).ready(...), which then went off to fetch the API results. This also set the UpdateProgress to visible which disappeared after the results had finished loading.

Button click event is not firing in jquery mobile dialog with ASP.net webforms

I am opening dialog using Jquery Mobile. Problem is that btnSend_Click event is not firing. What I am trying to do that keeping button and textbox in update panel and do post back and close dialog after ruining on code on serverside.
Sample here
Parent Page Button HTML
<a href="/Kiosk/RetrieveTickets/RetrieveTicketsBySms.aspx" data-role="button" data-inline="true" data-theme="c" class="MyBigButton"
data-inline="true" data-rel="dialog" data-transition="pop">Via SMS
<br />
<br />
<img src="/Kiosk/images/mobile.png" />
</a>
Dialog Page HTML
<div id="dlgSms" data-role="dialog" data-theme="b">
<div data-role="header" data-theme="d">
<h1>
Retrieve Tickets By SMS</h1>
</div>
<div data-role="content" data-theme="c">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p>
Please type here your mobile number. You will get your ticket on your mobile via
SMS.</p>
<asp:TextBox runat="server" ID="txtMobileNumber" placeholder="Enter Mobile Number" />
<asp:Button ID="btnSend" Text="Send SMS Now" runat="server" data-theme="b" OnClick="btnSend_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Cancel
</div>
</div>
I will describe you the main issue here.
When you click on the "Via SMS" button you open a dialog, and the script is load one diferent aspx page, the RetrieveTicketsBySms.aspx and renders it in the DOM of the previous. So the button and the update panel and the script of the RetrieveTicketsBySms.aspx is now history.
So the button its fire, but is call the RetrieveTicketsOptions.aspx page, that is not even have it, but also the hash validation is also fails, so its not fired. You also have it inside the update panel, so from what I see is not even make any post back.
The possible solution here is to place the content of the dialog, that loads the RetrieveTicketsBySms.aspx inside an iframe -if this is possible. and remove the UpdatePanel.

ASP.NET Partial postback issue

I have an ImageButton which, when clicked, calls a code-behind method that does some work and also changes the state of the ImageButton. I want to do a partial postback so that the entire page doesn't have to to load after clicking the ImageButton but also because I want the ImageButton as well as a Label next to it to update.
I figured I could use an UpdatePanel to accomplish this, but haven't had any luck. Here's what it looks like currently:
<asp:ScriptManager EnablePartialRendering="true" ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="entry-vote">
<div class="vote-left">
<asp:ImageButton ID="thumb" runat="server" OnClick="Cast_Vote" />
</div>
<div class="vote-right">
<span class="votecount"><%# Eval("Votes.Count") %></span>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
When I click the ImageButton, it appears to wait about five seconds and then execute the code behind.
I've never worked with partial postbacks before, so I'm kind of just flying blind here.
The delay only occurs while testing on localhost in Debug. Deploying in Release fixes the issue.

asp.net toggle button extender and modal popup extender collision

I am currently moving some form fields on an existing webform into a modal popup window using the asp.net toolkit extender. One of the fields uses the toolkit's toggle button extender on a checkbox a works quite well. When I move the checkbox and extender into the modal popup div, the toggle button extender stops working.
After confirming the problem, I decided to try using a jquery plug-in called checkbox that provides the same function. Again this plugin worked as advertised until I moved it into the modal window div. I had hoped to avoid hand rolling a solution.
I am guessing that the problem has something to to with css positioning. I would love to hear possible fixes before I build a solution from scratch.
Edit
Here is my original approach with toggle button extender:
<!-- works fine here -->
<asp:CheckBox ID="chkUSDAdd" runat="server" CssClass="PriceEntryToggle" Checked="true" Visible="false" />
<ajaxToolkit:ToggleButtonExtender ID="tglCurrencyAdd" runat="server"
TargetControlID="chkUSDAdd"
CheckedImageAlternateText="Click here to enter price in CAD"
UncheckedImageAlternateText="Click here to enter price in USD"
UncheckedImageUrl="~/images/ButtonCAD.gif"
CheckedImageUrl="~/images/ButtonUSD.gif" />
<asp:Panel ID="pnlAddTransaction" runat="server" Width="600px" Height="300px" CssClass="ModalWindow">
<!-- doesn't work here - outside UpdatePanel but inside modal window div-->
<asp:UpdatePanel ID="udpAddTransaction" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<!-- This is the desired location but doesnt work here -->
<asp:CheckBox ID="chkUSDAdd" runat="server" CssClass="PriceEntryToggle" Checked="true" Visible="false" />
<ajaxToolkit:ToggleButtonExtender ID="tglCurrencyAdd" runat="server"
TargetControlID="chkUSDAdd"
CheckedImageAlternateText="Click here to enter price in CAD"
UncheckedImageAlternateText="Click here to enter price in USD"
UncheckedImageUrl="~/images/ButtonCAD.gif"
CheckedImageUrl="~/images/ButtonUSD.gif" />
<!-- etc-->
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="hdnInvestmentID" />
</Triggers>
</asp:UpdatePanel>
<asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="mpeAddTransaction" runat="server"
TargetControlID="pnlAddTransaction" PopupControlID="pnlAddTransaction"
CancelControlID="btnCancel" OnCancelScript="hideAddTransactionPopup()"
BackgroundCssClass="modalBackground" />
I have also now tried placing a hidden field and an image and writing jquery click function. This also results in the same issue (stops working inside modal div).I can get code to run by hard coding onclick event attribute. I would love to understand why and if there are any more elegant ways to work around this. I guess I could try a jquery modal popup plugin, but I didn't plan to rewrite this whole page.
Take a look at your ModalPopupExtender Attributes. TargetControlID and PopupControlID are the same panel "pnlAddTransaction". The TargetControlID is the control that triggers the control at PopupControlID to display.

Resources