How to open SharePoint application page in modal dialog (popup) using c#? - 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;
}

Related

Prevent asp popup window from pop up blocker

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

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;
});

Can I use a Lync api in my asp.net application?

hi can I get the lync contacts and them status in a listview with C#? I want to get all users from ad to a listview in asp.net web application and control wheater a user is online or offline.
Yes you can. Check the following links to integrate lync in asp.net applications:
Lync integration:
http://sharpsplash.wordpress.com/2012/08/03/integrate-microsoft-lync-into-a-asp-net-web-application/
Show MS Lync presence status:
http://htmlpresencecontrols.codeplex.com/
If Carlos' links do go dead, here is the TL;DR. This Javascript taps into the NAME.dll in C:\Program Files\MicrosoftOffice\Office14:
<script>
$(function() {
//hide the ooui if the user scrolls.
(window).scroll(function() {
HideOOUI();
});
$('#lyncspan').hover(function() {
//show ooui on mouseover event
ShowOOUI();
}, function() {
//hide ooui on mouseout event
HideOOUI();
});
});
var sipUri = "your.contact#your.domain.com";
var nameCtrl = new ActiveXObject('Name.NameCtrl.1');
if (nameCtrl.PresenceEnabled)
{
nameCtrl.OnStatusChange = onStatusChange;
nameCtrl.GetStatus(sipUri, "lyncspan");
}
function onStatusChange(name, status, id)
{
//In a real world application you would display
//a status icon instead of an alert
alert(name + ", " + status + ", " + id);
}
function ShowOOUI()
{
nameCtrl.ShowOOUI(sipUri, 0, 15, 15);
}
function HideOOUI()
{
nameCtrl.HideOOUI();
}
</script>
<span id="lyncspan" style="border-style: solid">Your Contact<span>

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);

open in new tab of browser programmatically

i have a login page in fancy box and on click of login i want the secure pages open in the new tab
and uses this code
// on code at btnlogin_click
FormsAuthentication.RedirectFromLoginPage(loginID, false);
string redirectTo = GetResPath("/webPages/Default.aspx");
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "add2", "parent.jQuery.redirTo='" + redirectTo + "'; parent.jQuery.fancybox.close();", true);
//on aspx page
<script type="text/javascript">
$(document).ready(function () {
$('[id*=logn_btn_new]').fancybox({
'width': 480,
'height': 280,
'padding': 10,
'margin': 10,
'hideOnOverlayClick': false,
'scrolling': 'no',
'autoScale': false,
'transitionIn': 'none',
'transitionOut': 'none',
'type': 'iframe',
'onClosed': function () {
try {
if ($.redirTo != null && $.redirTo.length > 0) {
var pop = window.open($.redirTo, '_newtab');
if (pop == null) {
alert("Please allow popups.");
}
}
}
catch (err) {
alert(err);
}
}
});
});
</script>
and redirTo is hidden fielld.
i am not able to open page in new tab can anybody help?
This is a difficult one, as it is something that is controlled by the user's web browser settings.
The method that you are using is specific to FireFox and will indeed open a new tab. But this can still be overridden by the user's settings.
However to get the same effect in other browsers here is an article for IE Open a new tab in IE through Javascript
It is worth considering why you need to do this. Users may be confused if you open a new tab / window without informing them. Is it possible to not open a new window and keep everything in the same page? Then you know that people logically will have the same results to an extent.
I hope this helps!

Categories

Resources