How to reload parent page on open PopUp window in aspx - c#

On a master page when use clicks on it a popup window is displayed using this code :
queryString = "web.aspx?ds=" + Base64ForUrlEncode(ds.ToString())
newWin = "var Mleft = (screen.width/2)-(1200/2);var Mtop = (screen.height/2)-(700/2);window.open('" + queryString + ','_blank','height=700,width=1200,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\';'); window.opener.location.reload();";
ClientScript.RegisterStartupScript(this.GetType(), "pop", newWin, true);
How to reload parent page on open PopUp window?
I have tried with
window.opener.location.reload()
without success :
newWin = "var Mleft = (screen.width/2)-(1200/2);var Mtop = (screen.height/2)-(700/2);window.open('" + queryString + ','_blank','height=700,width=1200,status=yes,toolbar=no,scrollbars=yes,menubar=no,location=no,top=\'+Mtop+\', left=\'+Mleft+\';'); window.opener.location.reload();";
Thank you in advance for any help.

Do you have you tried re-bind the parent page after open popup ?

Related

PostBackUrl being overwritten in my jquery .load panel

In my C# web application, I have one page with a panel control:
ViewTask.aspx
<asp:Panel ID="panelImageThumbnails" runat="server" Style="width: 100%;">
This panel gets filled using jQuery .load with page ThumbnailPanel.aspx
<script type="text/javascript">
$(window).load(function () {
LoadThumbnails();
});
function LoadThumbnails() {
$("#panelImageThumbnails").empty();
var imglink = "<span style='text-align: center; align-content:center'>Getting thumbnails, please wait!<br><br><img src='Images/loader.gif'><br><br></span>";
$("#panelImageThumbnails").append(imglink);
$('#panelImageThumbnails').load('ThumbnailPanel.aspx').hide().fadeIn(1000);
return false;
}
</script>
Inside ThumbnailPanel.aspx, I query a table for a list of images and then loop over the DataTable and write them each to another panel each as ImageButtons
//Add a new image button to the thumbnail panel
ImageButton newImageButton = new ImageButton();
newImageButton.ID = "ib_" + row["Screenshot_ID"].ToString();
newImageButton.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bytes);
newImageButton.PostBackUrl = "ViewImage.aspx?fileName=" + row["Screenshot_ID"].ToString() + ".png";
newImageButton.OnClientClick = "target='_blank'";
newImageButton.CssClass = "thumbnailButton";
newImageButton.ToolTip = row["Screenshot_Created"].ToString() + "(" + row["Screenshot_CreatedBy"].ToString() + ")";
newImageButton.AlternateText = row["Screenshot_Title"].ToString();
panelUploadedImageThumbnails.Controls.Add(new LiteralControl("<table border='1' style='border-collapse: collapse;' class='inlineTable'><tr><td style='font-size:7pt;'>" + row["Screenshot_Title"].ToString() + "</td></tr><tr><td>"));
panelUploadedImageThumbnails.Controls.Add(newImageButton);
panelUploadedImageThumbnails.Controls.Add(new LiteralControl("</td></tr></table>"));
I set the PostBackUrl to page "ViewImage" and feed in the Screenshot_ID. This page converts the image to a bytearray and prints it to the screen.
ThumbnailPanel.aspx works perfectly on its own. But when it's loaded into panelImageThumbnails during the jQuery .load inside ViewTask.aspx all of the hyperlinks point to ThumbnailPanel.aspx instead of ViewImage.aspx.
Any idea how I can fix my desired PostBackUrl from being ignored?

MenuItem call javascript function

Dynamically building menu items and need to call a javascript function from one of them.
function popWin(url) {
var winHandle = window.open(url, '_blank', 'width=1000,height=700,resizable=yes,top=5,left=5,scrollbars=yes,status=yes');
}
<asp:Menu ID="Menu1" runat="server" StaticDisplayLevels="8" RenderingMode="List" OnMenuItemClick="Menu1_MenuItemClick" CssClass="menu" Width="150px">
</asp:Menu>
The code behind:
string url = "/somepage.aspx";
MenuItem child = new MenuItem();
child.Text = "Some Text";
child.NavigateUrl = "javascript:popWin('" + url + "');";
//child.NavigateUrl = "javascript:window.open('somepage.aspx');";
Menu1.Items[1].ChildItems.Add(child);
Just having some trouble calling the javascript function.
The window.open will work but an extra page opens and I need more control over the window opening.
The reason this needs to be done this way is there's an iFrame on the page that's loading different pages. The RegisterStartupScript was being used in the Menu1_MenuItemClick event but it was refreshing the source of the iFrame.
Thanks for any suggestions.
UPDATE
Trying to go another route on this but just not working right:
child = new MenuItem();
string win = "/SomePage.aspx";
string script = "popWin(" + win + ");";
string text = "<span style='cursor:pointer;' onclick='" + script + "'>Some Text</span>";
child.Text = text;
child.Selectable = false;
Menu1.Items[1].ChildItems.Add(child);
After coming back to this problem and testing a span tag in html with an onclick event, the problem was simply a bit of syntax:
child = new MenuItem();
string win = "/SomePage.aspx";
string script = "popWin('" + win + "');";
string text = "<span style=\"cursor:pointer;\" onclick=\"" + script + "\">Some Text</span>";
//Below is how it should render
//<span style="cursor:pointer;" onclick="popWin('/SomePage.aspx');">Some Text</span>
child.Text = text;
child.Selectable = false;
Menu1.Items[1].ChildItems.Add(child);
Thought I would post this just in case anyone else runs into the same issue.

opening a radwindow from a user control

How to open a radwindow on the click event of a Imagebutton within a user control?
Moreover i have used the same code in aspx page and it works fine.
car.ascx
code behind car.ascx.cs
protected void btnCarLogo_Click(object sender, ImageClickEventArgs e)
{
carurl="https://www.google.co.in/"
ScriptManager.RegisterStartupScript(this, this.GetType(), "popCarWindow", "window.radopen('" + carurl + "', 'CarDetails');", true);
}
It has VisibleOnPageLoad property. If you set it to true, window will be visible after postback.
Examples:
Show window
myRadWindow.VisibleOnPageLoad = true;
Hide window
myRadWindow.VisibleOnPageLoad = false;
Take a look here: http://www.telerik.com/community/forums/aspnet-ajax/window/opening-radwindow-from-the-server.aspx and see that the parameters are Page and not this (i.e. UserCOntrol).
Here is on working with JS functio nnames in user controls: http://www.telerik.com/support/kb/aspnet-ajax/general/using-dynamic-unique-names-for-javascript-functions.aspx
And, if you are going to have more than one manager on the page: http://www.telerik.com/help/aspnet-ajax/radwindow-troubleshooting-wrong-window-opened.html.
That way probably you get errors stating that the window is null
Try it like this:
Code behind:
string script = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(ShowWindow);</script>";
ClientScript.RegisterStartupScript(this.GetType(), "showWindow", script);
Then on your aspx:
<script type="text/javascript">
function ShowWindow()
{
var oWnd = window.radopen('https://www.google.co.in/', 'window1');
}
</script>

Open Popup with dynamicly generated Html from CodeBehind

At a certain point i have a dynamicly generated string with html in my code-behind.
I want to open a popup with has that html as its source.
I have tried the following:
I created this method on my .aspx site (Javascript):
function OpenWindowWithHtml(html, title) {
var myWindow = window.open('', title);
myWindow.document.write(html);
myWindow.focus();
}
And in the code-behind i have this:
Response.Write("OpenPopupWithHtml(\"" + html + "\", \"" + title + "\");");
But when i try to execute this i get an error.
Does anybody see, what i do wrong here?
Or does somebody know a better way to do this?
EDIT
on button click it shoudl be like this
protected void btnAbct_Click(object sender, EventArgs e) {
ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "OpenPopupWithHtml('" + html + "', '" + title + "');");
}
To execute the code ie. function you written in javascript
ClientScript.RegisterStartupScript(this.GetType(),
"newWindow", "OpenPopupWithHtml('" + html + "', '" + title + "');");
you can register client script like this
if (!ClientScript.IsClientScriptBlockRegistered("exampleScript"))
ClientScript.RegisterStartupScript(this.GetType(), "exampleScript","
<script language = "'javascript'">
alert('you just registered the start up script')
</script>
");
from the code behind file of asp.net
To Open pop-Up window , just replace this line in above code
ClientScript.RegisterStartupScript(this.GetType(),
"newWindow", String.Format("<script>window.open('{0}');</script>",
"mypage.html"));
Check this for detail : Register Client script in ASP.NET

Block popup windows settings give error to close popup window in JavaScript

I have one web page, on which when user click on button (for calculation purpose) one popup window open (it's an aspx page as popup) .
When user done calculations on popup then automatically popup is close.
But when user block popup windows through browser setting then popup open but can't close.
I want to close this popup window even when user block popup windows.
Code for open popup window:
window.open('frmSelection.aspx?form=' + formname + '&controlname=' + controlname + '&caption=' + caption + '&control1=' + control1 + '&control2=' + control2 + '&control3=' + control3 + '&Filter=' + filter + '', null,
'height=500,width=562,status=yes,toolbar=no,menubar=no,location=center');
Code for close popup window:
protected void dgrdSelection_ItemCommand(object source, DataGridCommandEventArgs e)
{
if (e.CommandName == "Select")
{
StringBuilder strScriptBuilder = new StringBuilder();
strScriptBuilder.Append("<script language='javascript' type=text/javascript> ");
strScriptBuilder.Append(" window.close(); ");
strScriptBuilder.Append(" </script> ");
}
}
Try use jQuery load() with jQueryUI dialog(), like this. So have no problem with popup blocker.

Categories

Resources