After open pop window, i need to reload my page. here page gets reloaded but pop window not opened. How to solve it.
string url = "Popup.aspx";
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
Response.Redirect("~/mysamepage.aspx", false);
Have you tried a Reload in the javascript by appending it to the s string:
window.location.reload(false);
// If you need to fetch the webpage from the web-server again (where the page
//contents change dynamically) pass the argument as 'true' instead of 'false'.
eg
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');window.location.reload(false);";
or try:
window.opener.href('url').reload(true);
Related
I have a scenario where I loop through a data set (max of 6 records) and then open a new browser tab for each record - each tab shows an invoice for one of the records - not the best design but it's what was requested.
I'm using the code below within a foreach to build a url and open a new browser tab, the problem is it loops through ok but only ever opens 1 new tab.
Every other thing happening in the loop works so the problem seems to be with the code. It opens the first tab for the first record then no more after that.
Can anyone comment on what's wrong?
string pageurl = "Label.aspx?booking=" + v.booking + "&pallet=" + v.palletId;
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", "window.open('" + pageurl + "','_blank')", true);
You can only have one startup script. Try putting all of your window.open calls in a single script;
//This code inside loop
string pageurl = "Label.aspx?booking=" + v.booking + "&pallet=" + v.palletId;
string script += "window.open('" + pageurl + "','_blank'); "
//This code outside loop
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "popup", script, true);
I have a "error.aspx" page which is there to mail me if any exception is caught. When I open the page manually, mysite.com/error.aspx, the page opens fine but when it is redirected by a catch block with the exception.message and exception.stackTrace as querystrings, I get an error "page not found". Are the querystrings directing the browser to open a different url? It works fine when run on localhost, though.
public void send_error(Exception ex)
{
Response.Redirect("error.aspx?time=" + DateTime.Now.ToString() + "&ex=" + ex.Message + "&st=" + ex.StackTrace.Replace("\n", " "), false);
}
If you check this Article, you will see that the max query length of url string is 2048 symbols for Internet explorer. Probably the url is bigger and because of that you have this problem. One solution is to save the desire message in the session as string and after that retrieve it on other pages.
string errorMessage = DateTime.Now.ToString() + " " + ex.Message + " " + ex.StackTrace.Replace("\n", " ");
Session["__ErrMessage"] = errorMessage;
When you are in other pages you can access this string like this:
string errMessage = "";
if(Session["__ErrMessage"] != null)
errMessage = Session["ErrMessage"].ToString();
I was requested to add some searching functionality to an existing system for the collection of PDFs that we have. I know about searching PDFs and opening them with search parameters and in a test application I wrote, it works like a dream. When trying to convert it over to our existing application the PDF opens but without the search terms or the advanced find of Acrobat Reader popping up. Any help would be greatly appreciated!
Here is a snippet of the cs code :
case "PDF":
string searchTerms = SearchWordsTB.Text;
searchTerms = searchTerms.Replace(',', ' ');
launchStr = "OpenPDF('" + e.Row.Cells[9].Text.Replace("\\", "/") + "','" + HttpUtility.UrlEncode(e.Row.Cells[2].Text) + "','" + e.Row.Cells[0].Text + "','" + searchTerms + "')";
break;
We are creating the list of documents on the fly and PDF is one of the options. Assuming I am understanding this correctly, A DataGrid is created with all these clickable rows that will execute a Javascript function when clicked. The Javascript function OpenPDF is shown below:
function OpenPDF(url, filename, ID, searchTerms) {
if (searchTerms.length > 0) {
window.open('FileViewer.aspx?name=' + filename + '&ID=' + ID + '&url=' + url + '#search="' + searchTerms + '"', 'mywindow' + windowCnt, 'width=800,height=600,location=no,resizable=yes');
}
else {
window.open('FileViewer.aspx?name=' + filename + '&ID=' + ID + '&url=' + url, 'mywindow' + windowCnt, 'width=800,height=600,location=no,resizable=yes');
}
windowCnt++;
}
From following the debugging in the CS code, I know that I am properly stripping out the commas in the search terms so that shouldn't be the problem. What currently happens is the PDF file will open up just fine, but the search terms are not being used. I have tried following the debugger through the Javascript (which for me has always been spotty at best) but the breakpoint is never hit. It should also probably be noted that the Javascript function is kept in a separate Javascript File and is not inline in the aspx page. And yes, we are correctly referencing the Javascript file. I will be more than happy to update this post with any extra info that is requested. Thanks in advance for any help!
I was able to achieve the desired results by using the http encode on the launch string as shown below.
launchStr = "OpenFile('" + HttpUtility.UrlEncode(e.Row.Cells[9].Text.Replace("\\", "/") + "#search=\"" + searchTerms + "\"") + "','" + HttpUtility.UrlEncode(e.Row.Cells[2].Text) + "','" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "')";
I then used the function to just open the window with the PDF in it. The problem I had was that without the HTTP Encode, the URL was just cutting off the search parameters. I believe this is because the #search="blah" isn't normally recognized as part of a URL and was therefore truncated. If anyone has a better reason, I would love to hear it.
I am making the users download a file on an anchor tag click. On its onclick event, i have used __doPostBack to partial post back the page to return the file which is downloadable by the user.
Now the problem i am facing is, that when the file is not found, the page reloads and the ajax calls are not set. So, in short, when the browser is expecting a response after _doPostBack function, and does not get one, it reloads the page but $.ajax methods do not run. What am i missing? Should I do something with the response? or is there any way that the response can be cancelled? Please help.
The anchor tag is, for instance
<a onclick="javascript:__doPostBack('AnnouncementAttachmentDownload','Ch 7 -Software Design2010.doc')">Ch 7 -Software Design2010.doc</a>
The server side code is
protected void Page_Load(object sender, EventArgs e)
{
SetPageTitles(ModuleNames.NotSpecified, null, false, true, true, false);
if (this.Request.Params["__EVENTTARGET"] == "AnnouncementAttachmentDownload")
{
string FileName = this.Request.Params["__EVENTARGUMENT"].ToString();
string destinationPath = Server.MapPath("~/" + System.Web.Configuration.WebConfigurationManager.AppSettings["AnnouncementAttachmentsPath"]).ToString() + "\\";
if (System.IO.File.Exists(destinationPath + FileName))
{
Response.AppendHeader("content-disposition", "attachment; filename=" + FileName);
Response.TransmitFile(destinationPath + FileName);
Response.End();
}
else
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "NewScript", "alert('The requested file could not be found, please contact portal.production.support');", true);\\DOESNT WORK
}
}
}
The line in the else part, it just shows the message but the page loads after that too.
On the file not being found, i used Responce.Redirect to redirect it to the current page again, before that I stored a bool in a session variable, and on pageload i checked the session variable if it contained some value and then showed the message. Also, i cleared the session too on in the above if expression.
Code :
string url = "http://www.google.com";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "UrlSocialDefinitivo", "var UrlSocialDefinitivo=" + Server.UrlEncode(url) + ";", true);
but I get (on browser console) : SyntaxError: identifier starts immediately after numeric literal.
In fact it registers UrlSocialDefinitivo=http%3a%2f%2fwww.google.it;
Where am I wrong? How can I resolve this trouble?
It miss the quotes around the string :
string url = "http://www.google.com";
ScriptManager.RegisterClientScriptBlock(
this,
this.GetType(),
"UrlSocialDefinitivo",
"var UrlSocialDefinitivo=\"" + Server.UrlEncode(url) + "\";",
true
);
That will produces :
UrlSocialDefinitivo="http%3a%2f%2fwww.google.it";
Note that I'm not sure you have to keep the Server.UrlEncore call. It depends on the format you are expecting actually.
You need to surround the url string in quotes or the javascript interpreter will assume it is javascript to be executed (and fail miserably).
ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
"UrlSocialDefinitivo",
"var UrlSocialDefinitivo='" + Server.UrlEncode(url) + "';", true);
// quotes here ^ and here ^