I am opening a popup window B from page A using:
this.Page.ClientScript.RegisterStartupScript(
this.GetType(),
"JavaScript",
"myWindow=window.open('B.aspx',
'WindowName',
'copyhistory=no,
width=800,
height=300,
top=150,
left=50,
resizable=1,
scrollbars=1');
myWindow.focus();",
true
);
I want to refresh page A whenever there is a change in popup window B.
There are many ways to do it:
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
<script language="JavaScript">
<!--
function refreshParent() {
window.opener.location.href = window.opener.location.href;
if (window.opener.progressWindow)
{
window.opener.progressWindow.close()
}
window.close();
}
//-->
</script>
Sources:
Open popup and refresh parent page on close popup
http://forums.devarticles.com/javascript-development-22/auto-refresh-parent-window-after-closing-popup-4864.html
Refresh parent window when the pop-up window is closed
Call refreshParent on user actions as :
function refreshParent() {
window.opener.location.href = window.opener.location.href;
}
Related
I have a modal popup that shows an IFrame. The IFrame then points to an aspx that has a button. The button's class is schedule-submit.
When I click that button in the IFrame, I want it to close the modal on my page.
I tried this in the document ready of the page that has the IFrame:
$('.schedule-submit').bind('click', function() {
closeEditModal();
});
But it is not having any effect.
What should I do to get this working?
Thanks
You need to call it from the parent page where you have the modal popup with iFrame:
var $MyFrame = $("#iframeid");
// You need to wait for the iFrame content to load first
// So, that the click events work properly
$MyFrame.load(function () {
var frameBody = $MyFrame.contents().find('body');
var btn = frameBody.find('.schedule-submit');
btn.on('click', function() {
closeEditModal();
});
});
Currenly i am working on asp.net c# project.
I use select2 in update panel.
My button Click is not working after Postback.
I use this Code to rebind this JQuery Plugin in update panel.
<script type="text/javascript">
var frm = document.getElementById("aspnetForm");
if (frm) {
frm.onsubmit = function () { return false; };
}
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
if (args.get_error() == undefined) {
bind();
}
}
function bind() {
$(document).ready(function () {
$(".chzn-select").select2();
$(".option-listing").select2();
});
}
</script>
After postback button click is not working only in IE9. No Console Error..
In other browser work properly.
If i Comment this Bind() function my button is work properly.
You can check here if your jquery framework is compatible with ie9
http://msdn.microsoft.com/en-us/library/ie/hh180175%28v=vs.85%29.aspx
In my ASP.NET application, my popup window is returning null for a specific variable.
When I click a button this JavaScript gets fired:
function Picker_OrderDefaultFirst() {
OpenPageWithParam('OrderPermanentItems', '?ID=' + "<%=CommitteeUId %>" + "&btn=1", returnOrderPicker);
return false;
}
returnOrderPicker looks like:
function returnOrderPicker() {
alert("Test fra returnOrderPicker");
}
OpenPageWithParam looks like:
function OpenPageWithParam(PageName, Query, ReturnFunction) {
var _window = null;
InitBlocker();
switch (PageName) {
case "OrderPermanentItems":
_window = PopupCenter(ROOT_DIR + "/Forms/Pickers/PermanentItemsPicker.aspx" + Query, PageName, 590, 600);
break;
}
_window.ReturnFunction = ReturnFunction;
return _window;
}
I'm setting the popup window's property ReturnFunction to be ReturnFunction of data from previous page. (In this example returnOrderPicker Function).
But, when window pops up, the value of window.ReturnValue is undefined.
Calling in popup window looks like:
<script type="text/javascript" language="javascript">
window.onload = function (sender, eventArgs) { alert(window.ReturnFunction + " Window PermanentItemPickerPopup "); }
</script>
Any ideas?
I am using a javascript to zoom an image on my asp.net web page. I want to put 2 buttons on it like "Zoom" "Cancel Zoom" and accordingly activate/deactivate the javascript functionality. Right now I have a css class on which the javascript operated to produces the zoom effect. The image is like:
<a id="big" href="source of image" class"classforzoom">
<img id="small" src="some small image on page" />
</a>
<script type="text/javascript">
$(document).ready(function () {
var options = {
//some code here
};
$(".jqzoom").jqzoom(options);
});
</script>
How do I programmatically do this on the onClick events on the 2 buttons?
This is what I am using in the head tag of my page:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
Related toggleclass() method:
toggleClass: function(F,E) {
if(typeof E!=="boolean") {
E = !o.className.has(this,F)
}
o.className[E?"add":"remove"](this,F)
}
Deactivate
$("a#cancelzoom").click(function(event)
{
$('.classforzoom').unbind();
event.preventDefault();
});
Activate
$("a#zoom").click(function(event)
{
$('.classforzoom').jqzoom(options);
$('.classforzoom').bind();
event.preventDefault();
});
Did you check out the jQuery click method and then use the unbind method to remove an event from an object?
Also since you say you are using a css class for the zoom effect check out the toggleClass() method.
I have a masterpage with a Login Control in it. When the Login button is clicked, I would like for a JQuery Dialog to popup if the user's membership is about to expire within 30 days, else it will just log them in as normal. I can't figure out how to do it. I wll post parts of code:
Here is the javascript:
<script type="text/javascript">
function showjQueryDialog() {
$("#dialog").dialog("open");
}
$(document).ready(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true,
buttons: { "Renew Membership": function()
{ $(this).dialog("close"); } }
});
});
</script>
The login button is called ibtnLoginButton and here is part of the code:
//Grab the user profile.
UserProfiles userProfile =
UserProfiles.GetUserProfiles(txtUserName1.Text);
//Calculate the Time Span
TimeSpan timeSpan = userProfile.Expiration.Subtract(DateTime.Now);
if (timeSpan.Days < 30)
{
//Show JQuery Dialog Here
}
else
{
//Continue with Login Process.
}
how about this?
if (timeSpan.Days < 30)
{
//Show JQuery Dialog Here
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "showExpiration", "showjQueryDialog()", true);
}
If, as you've said you've got this jQuery dialog to appear when clicking an asp:Button, why not just hide the button and change your javascript to just press the button once the page has loaded?
Why not always call the jquery method when the button is clicked, and then determine within the javascript method whether or not you want to show the dialogue? If not, just don't do anything. Since you're just checking whether ExpirationDate is smaller than now + 30 days, you can do that calculation just fine in javascript.
Edit:
I can't provide you with the exact solution, but here is some pseudocode to get you on your way.
First make the user profile's expiration date need available in javascript:
<script>
var userProfileExpiresOn = "<asp:Literal ID="userProfileExpiresOn" />";
</script>
Then edit your method so that it does the logic you're currently doing server-side for you:
<script>
function showjQueryDialog() {
if (userProfileExpiresOn < (now + 30 days))
$("#dialog").dialog("open");
}
</script>
You can find some documentation on how to work with dates in Javascript at W3schools.