Prevent asp popup window from pop up blocker - c#

I am using the following code to get popup window in asp .net before sending text in database. But due to popup blocker pop up dose not come.
string strPopup = "<script language='javascript' ID='script1'>"
// Passing intId to popup window.
+ "window.open('sharepopup.aspx?data=" + HttpUtility.UrlEncode(intId.ToString())
+ "','new window', 'top=90, left=200, width=500, height=500, dependant=no, location=0, alwaysRaised=no, menubar=no, resizeable=no, scrollbars=n, toolbar=no, status=no, center=yes')"
+ "</script>";
ScriptManager.RegisterStartupScript((Page)HttpContext.Current.Handler, typeof(Page), "Script1", strPopup, false);
cmd = new SqlCommand("Insert Into ChatTB values(column names) ", con);

You can't - because that's what popup blockers do: they block popup windows (i.e. calls to window.open or invocations of target="_blank" links) unless it is directly in response to a user mouse action.
Alternatively you can use Jquery
$("#dialog-message").dialog({
modal: true,
draggable: false,
resizable: false,
position: ['center', 'top'],
show: 'blind',
hide: 'blind',
width: 400,
dialogClass: 'ui-dialog-osx',
buttons: {
"ok": function() {
$(this).dialog("close");
}
}
});
Here is the fiddle

Related

How to pass value to jquery dialog?

How to get pass id value of button to jquery dialog on button click.
I don't want to pass value using query string.Is there any way that i can directly pass value using attributes or properties of jquery dialog.
View:
<input type="button" value="Create New" class="Create" id="1"/>
Jquery:
$(".Create").on("click", function (e) {
var Id=$(this).atrr('id');
$('#Load').empty();
//overflow: visible !important;
e.preventDefault();
$('#Load').dialog({
autoOpen: true,
modal: true,
draggable: true,
resizable: false,
height: 500,
width: 600,
position: { my: "center", at: "center", of: window },
dialogClass: 'fixed-dialog',
title: 'Create New Word',
open: function (event, ui) {
$(this).load("/Dictionary/_Create");
},
//close: function (event, ui) {
// window.location.href = window.location.href;
//}
});
return false;
});
You can change this line
var Id=$(this).atrr('id'); To BTW atrr is suppose to be attr
CurrentId = $(this).attr('id'); without the var
Then in the page /Dictionary/_Create you can simple access the CurrentId variable using javascript since it's global

How to display the content in popup window?

Iam creating a button "SampleTest", which wil have to show the model data and "GoBack" button in popup window.But it displaying the content in full screen popup also overriding.Like,
i have my jquery like,
$('#SampleTest').button().click(function () {
var options = {};
options.type = "POST";
options.url = "/Dashboard/SampleTest/";
options.dataType = "json";
options.contentType = "application/json";
options.success = function (data) {
alert(data);
$(".popup").html(data);
$(".trasparentDiv").show(data);
$(".popup").show(data);
};
$.ajax(options);
});
Do i need to include any function in my jquery for popup window.Kindly tell me what to do in this case.
Please include JQuery UI script with appropriate version into your page after JQuery core script file.
Jquery UI CDN Path from JQuery: https://code.jquery.com/ui/
More help about Jquery Popup: http://jqueryui.com/dialog/
i have rewritten the code like,
function LoadSampleTest() {
alert('sample');
$("<div></div>")
.attr('id','SampleQuestionDiv')
.appendTo("body")
.dialog({
modal: true,
Close: function () {
$(this).dialog("close");
},
Width: 1000,
height: 800,
title: "Sample Test"
}).load("/dashboard/sampletest/");
Its works good.Instead of OK button, i have given close option to close the popup.

How to open SharePoint application page in modal dialog (popup) using c#?

Some times there is requirement to open a SharePoint application page as a popup. So how can a SP application page be opened as a popup using C# ?
C# Code:
void OpenApplicationPageAsPopup(){
string strWebUrl = SPContext.Current.Web.Url;
string strPageURL = strWebUrl + "/_layouts/MyLayoutFolder/MyPage.aspx";
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), ClientID, "ExecuteOrDelayUntilScriptLoaded(openModelDialogPopup('" + strPageURL + "'), \"SP.js\");", true);
}
JavaScript Code:
function openModelDialogPopup(strPageURL ) {
var dialogOptions = {
title: "This is Modal Dialog", //Popup title.
url: strPageURL,
width: 600, // Width of the dialog.
height: 400
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', dialogOptions);
return false;
}

How to close browser window with a dialog popup using jQuery function?

I am working on a project but need to know how to close the browser window and also show a dialog box if I would like to exit the page, using jQuery.
Thanks Rick, this helps, it brings up the dafault chrome pop up dialog, I am trying to customize it to use my dialog in my javascrip file so it can prompt it when the user closes the page.. here is my code function ConfirmationDialog(baseURI) {
var dialog = jQuery('Are you sure you want to exit this form without saving?').attr({
type: 'hidden',
id: 'dialog'
}).css("display", "none").appendTo('body');
jQuery("#dialog").dialog({
resizable: false,
height: 140,
modal: true,
title: 'Confirm',
buttons: {
"Yes": function () {
window.location = baseURI;
// jQuery(this).dialog("close");
},
Cancel: function () {
jQuery(this).dialog("close");
}
}
});
return false;
}
To close browser:
window.close();
To prompt user:
window.addEventListener("beforeunload", function (e) {
var message = "Are you sure you want to leave?";
(e || window.event).returnValue = message;
return message;
});

Redirect parent page to specified url on Submit inside fancybox

i am using fancybox and after submiting my form i want to redirtect my parent page to some specified url i am using fancybox as below
$(document).ready(function () {
$('[id*=addnewRequest]').fancybox({
'width': 760,
'height': 540,
'padding': 0,
'margin': 0,
'hideOnOverlayClick': false,
'scrolling': 'auto',
'autoScale': false,
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'iframe',
'centerOnScroll': true,
'onClosed': function () {
if ($.redirTo != null && $.redirTo.length > 0){
window.location.replace($.redirTo);
}
else {
parent.location.reload(true);
}
}
});
});
and after submiting my form i am using below register script where 'redirectTo' is url where i want my parent page will redirect
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "add", "parent.jQuery.redirTo='" + redirectTo + "'; parent.jQuery.fancybox.close();", true);
Now how my parent page will redirect to perticular url.Any idea?
thanks,
After submiting your form you can direct call the window.top.location.href with the new url as:
window.top.location.href = "http://www.urltogo.com/pagetomove.aspx";
and avoid to send parameters on the parent and from there make the redirect.
Here is an example (I add 5 second delay to have the time to see it)
http://jsfiddle.net/u6whQ/3/ or http://jsfiddle.net/u6whQ/4/
Your line will probably be as:
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "add", "window.top.location.href ='" + redirectTo + "'; parent.jQuery.fancybox.close();", true);

Categories

Resources