Please excuse my terminolgy, I am not used to discussing in detail
I have a fairly complicated page, containing various asp controls. One of which is a dynamically populated datagrid. Rows on this datagrid can be clicked and then within the SelectedIndexChanged Event on the grid I am working out several values and passing them as query strings into a URL and am then using response.redirect to open the URL as a new page with the parameters available to it. This works fine.
Response.Redirect("'MyPage.aspx?Sdate=" & sdate & "&Edate=" & edate & "&AreaCode=" & AreaCode & "&Qsdate=" & Qsdate & "&Qedate=" & Qedate & "")
The problem is that the whole page is wrapped in an Ajax Update Panel, for various reasons, and I now need to open the new page (after clicking a row on the datagrid) in a new browser window.
The usual method I think would be -
Response.Write("<script>window.open 'MyPage.aspx?Sdate=" & sdate & "&Edate=" & edate & "&AreaCode=" & AreaCode & "&Qsdate=" & Qsdate & "&Qedate=" & Qedate& "', '_new','width=400, height=200');</script>")
BUT... I gather Response.Write can't be used with Ajax and when I have tryed it, I just aget a parsing error. Can anyone suggest how I can open a new browser window from the SelectedIndexChanged Event, whilst still keeping the datagrid within the Ajax update panel.
You can add a label, and make it initially invisible.// Label1.Visible =false;
Assign the Text property of that label, the java script you want to execute.
And on the SelectedIndexChanged event set the visibility of the Label to true and text to the javascript.
Label1.Text = "<script>window.open 'MyPage.aspx?Sdate=" & sdate &"&Edate=" & edate & "&AreaCode=" & AreaCode &"&Qsdate=" & Qsdate & "&Qedate=" & Qedate& "','_new','width=400, height=200');</script>";
Label1.Visible = true;
But, basically, you could do all of that on the client side. I see no reason why you make a post back, if you just append some values from the client side and concatenate them.
That still won't work with Ajax, I think that might be due to the way the event fires on the datagrid? It is making the lable visible and setting the text to that of the javascript when I debug, but once the page is loaded it just highlights the row selected and nothing else, the label is not even visible.
I don't think this method is right for what I am trying to achieve anyway, as there are variable values in my VB Code behind that need to be passed to the URL.Therefore how can I actually pass values held in vb.net variables into the javascript code?
i.e. - "<script>window.open 'MyPage.aspx?Sdate=" &sdate& "'
sdate is a variable that is used in my vb.net code that holds a date and I need that to be in the URL that is used in the javascript, same as all the other variables above - edate, areacode, etc.
Any other suggestions?
*Bump*
jaYKay:
Response.Write("<script>window.open 'MyPage.aspx?Sdate=" & sdate & "&Edate=" & edate & "&AreaCode=" & AreaCode & "&Qsdate=" & Qsdate & "&Qedate=" & Qedate& "', '_new','width=400, height=200');</script>")
Check what isRegisterStartupScript(Page, Type, String, String, Boolean) for a server side solution, or seeASP.NET AJAX Client Life-Cycle Events. if you need a client side solution.
Did you ever find a solution to this problem? I have the exact same situation and have spent the last 2 days trying to find a way to open a new browser window with dynamic values.
If you or anyone else has a solution to ths problem, could you please post it?
Thanks,
Ken
Hi, I've just coded a way of doing that..it's really ugly one, but this is what I can think of at this moment :)
Here is the web page code:
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
<!--
function PopUp()
{
var label = document.getElementById('Label1');
if(label!=null)
{
window.open(label.innerText);
}
}
//-->
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" visible="false" style="visibility:hidden" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
<script language="JavaScript" type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(EndRequest);
function EndRequest(sender, args) {
PopUp();
}
</script>
</body>
</html>
and the code behind (in c#):
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "http://www.asp.net";
Label1.Visible = true;
}
}
Hope this will help.
Cheers,
Yani
I was not able to get this variation to work, however on another thread I did get an answer that does work and is much cleaner.
Try this
http://forums.asp.net/p/1114996/1730089.aspx#1730089
Thank you very much for your reply.
Ken
I ended up cheating it really. I just used two panels on top of each other and made the first one and its contents disappear and the second one reappear, therefore giving the illusion that it was a new page, only problem now is that the information for the user is at the top of the second panel and the grid they clicked on is at the bottom of the first so they always have to scroll up to the top of the page each time. It works, if not a bit messy, I just need to set the focus to the top of the page, which is not that simple as the page is not refreshing as such and contains data that was parametised by the user.
Hi,
Have you looked at this thread http://forums.asp.net/t/1122462.aspx . I have posted a solution for similar problem in this thread. I hope this should solve your problem instead of doing it the above way. If you have any queries let us know.
No comments:
Post a Comment