I am hoping that this is a simple problem. I have a page that has a button the code for that button is as follows.
protectedvoid btnServerSearch_Click(object sender,EventArgs e)
{
string scriptStr ="<script type=text/javascript>window.open('FrmLoanSelect.aspx',null,'height=400,width=650');</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(),"Pop", scriptStr);
txLoanNumber.Text = (string)Session["DaData"];
}
When I click the button the new page displays beautifully in a window, in the dimensions that I requests. The code that is setting the session variable "DaData" is in the page being displayed as follows.
protectedvoid GridView1_SelectedIndexChanged(object sender,EventArgs e)
{
Session["DaData"] = GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text;
}
The problem appears to be that the main form is not waiting on the form it just displayed and therefore the session variable doesnt exist yet. Is there some way to make the main form wait for the exit of the popup form ? Or am I going to have to find some other way of passing the data from the popup form ?
Any input that anyone has is mughty appreciated!!
Bump for the non-weekend crowd.Hi,
The solution lies in using Modal Pop ups.
I have put together a small example for you.
In the calling (main page) use a client script to open up a modal window.
Main Page Code Behind
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onClick", "ShowPop();");
}
protected void Button1_Click(object sender, EventArgs e)
{
string x= (string)Session["X"];
}
}
javascript:
function ShowPop()
{
var win = window.showModalDialog('PopUpWindow.aspx', '', 'dialogHeight: 200px; dialogWidth: 300px; help: No; resizable: No; status: No;');
}
Called Page, Pop Up. Code Behind
ublic partial class PopUpWindow : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["X"] = TextBox1.Text;
string scriptStr = "<script type=text/javascript>window.close();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Pop", scriptStr);
}
}
This way, ur main page calls a popup, the pop up sets a value in session and closes itself( all this while the main page is still active)
The main page button on click gets invoked and it can access the value set in session
lemme know if this helps.
Deepak.
Thank you very much for the response!!
I think that I am 90% of the way there. The better news is that I managed to learn a LOT from your post :) I finally grasped that you can add client side event handlers to a server control using the attribute.add method.
That problem that I am encountering now is, I think, insurmountable, at least it seems that way to me. I am displaying a grid in my popup window, and when ever I select an entry in the grid, or try to select a different page on the grid its doing a postback, and that is giving me an error. The error details ( as seen in the Internet Explorer Error box ) Line: 1 Char: 1 Error: Object Expected Code: 0 URL: javascript:__doPostBack('GridView1','Page$6'). This specific error message was displayed when I tried to swap to page 6 of the gridview. When I try to select a specific value in the grid the message changes in the URL: portion to URL: javascript:__doPostBack('GridView1','Select$7').
This though makes sense to me that I am getting these errors, as I am trying to do a postback on a form that I specifically invoked as Modal. If I am wrong in this and Ive missed somthing I would love to hear it!
Once again thank you greatly for the help!!
Vince Campanile
A few things to look for:
1) Make sure you do not have any javascript syntax errors
2)If the script is in diff file, make sure you have included the src in ur script declaration
If you can paste ur code template, I can try to see the issue.
From a first glance looks like its lookin for a function and its not finding it...
HTH
Deepak.
Not sure what your refering to when you ask about the script. Do you mean the Script thats actually calling the modalDialog ?
Here is the entirety of the window that I am creating, with the exception that I have redacted out the database information
<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="FrmLoanSelect.aspx.cs" Inherits="BrokeredLoans.FrmLoanSelect" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Select Loan</title></head><body> <form id="form1" runat="server"> <div> <asp:GridView ID="gvLoanSelections" runat="server" AutoGenerateColumns="False" DataKeyNames="loanMasterID" DataSourceID="dsLoanSelect" Height="138px" Width="638px" AllowPaging="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" OnSelectedIndexChanged="gvLoanSelections_SelectedIndexChanged"> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="loanNumber" HeaderText="Loan Number" SortExpression="loanNumber" /> <asp:BoundField DataField="borrowerFirstName" HeaderText="First Name" SortExpression="borrowerFirstName" /> <asp:BoundField DataField="borrowerLastName" HeaderText="Last Name" SortExpression="borrowerLastName" /> <asp:BoundField DataField="fundedDate" HeaderText="Funded Date" SortExpression="fundedDate" /> </Columns> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /> </asp:GridView> </div> </form></body></html>
Here is the code behind page that is for that web page.
namespace BrokeredLoans{public partialclass FrmLoanSelect : System.Web.UI.Page {protected void gvLoanSelections_SelectedIndexChanged(object sender, EventArgs e) { Session["DaData"] = gvLoanSelections.Rows[gvLoanSelections.SelectedIndex].Cells[1].Text;string scriptStr ="<script type=text/javascript>window.close();</script>"; ClientScript.RegisterClientScriptBlock(this.GetType(),"Pop", scriptStr); } }}
The code that is calling the popup is as follows.
<script type="text/jscript"> function ShowPopup() { var win = window.showModalDialog('FrmLoanSelect.aspx','','dialogHeight=400,dialogWidth=725,resizable: No;status: No'); }</script>Thank you so much for taking the time out to help this newby along! :)
Another little tidbit of information...
I added another button to just plain show the search screen and when I make a selection there, or change the page no error is encountered and the search screen closes itsself like it should.
So as far as I can tell its somthing to do with the showl ShowModalDialog call.
Put <base target="_self" /> in the <head> ... </head> section of the page to be displayed in the modal window
You can make use of cross post back
=========
Cross-Page Posting
One common feature in ASP 3.0 that is difficult to achieve in ASP.NET 1.0/1.1 is the capability to do
cross-page posting. Cross-page posting enables you to submit a form (say,Page1.aspx) and have thisform and all the control values post themselves to another page (Page2.aspx).Traditionally, any page created in ASP.NET 1.0/1.1 simply posted to itself, and you handled the control
values within this page instance. You could differentiate between the page's first request and any postbacks
by using thePage.IsPostBackproperty, as shown here:
If Page.IsPostBack Then
' deal with control values
End If
Even with this capability, many developers still wanted to be able to post to another page and deal with
the first page's control values on that page. This is now possible in ASP.NET 2.0, and it is quite a simple
process.
For an example, create a page calledPage1.aspxthat contains a simple form. This page is shown in<title>First Page</title>
</head>
<body>
<form id="form1" runat="server">
Enter your name:<br />
<asp:Textbox ID="TextBox1" Runat="server">
</asp:Textbox>
<p>
When do you want to fly?<br />
<asp:Calendar ID="Calendar1" Runat="server"></asp:Calendar></p>
<br />
<asp:Button ID="Button1" Runat="server" Text="Submit page to itself"
OnClick="Button1_Click" />
<asp:Button ID="Button2" Runat="server" Text="Submit page to Page2.aspx"
PostBackUrl="Page2.aspx" />
<p>
<asp:Label ID="Label1" Runat="server"></asp:Label></p>
</form>
</body>
</html>
C#
<%@. Page Language="C#" %>
<script runat="server">
protected void Button1_Click (object sender, System.EventArgs e)
{
Label1.Text = "Hello " + TextBox1.Text + "<br />" +
"Date Selected: " + Calendar1.SelectedDate.ToShortDateString();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
TextBox pp_Textbox1;
Calendar pp_Calendar1;
pp_Textbox1 = (TextBox)PreviousPage.FindControl("Textbox1");
pp_Calendar1 = (Calendar)PreviousPage.FindControl("Calendar1");
Label1.Text = "Hello " + pp_Textbox1.Text + "<br />" + "Date Selected: " +
pp_Calendar1.SelectedDate.ToShortDateString();
}
</script>
0 comments:
Post a Comment