?
Solved

JavaScript:  Open/Close window on link click in C#

Posted on 2008-06-23
6
Medium Priority
?
4,221 Views
Last Modified: 2008-07-08
Background info:

I have a form, this form has a text box for searching and a button to search.  
On button click, a new window is opened with a gridview control that populates based on the search criteria entered in the main page. This grid view has buttonfield elements that allow the user to open form documents (insurance application) pre-populated with previously entered data.  

What happens on the click event of one of these buttonfields is I call a javascript function that calls the codebehind first to set sesson variables(not using query strings at all, so all insurance application ID information is set to a session variable).  Once the session variables are set, the page redirects to the specific url of the particular referenced applcation/form.

My problem is:  I have opened an insurance application for Client "A", I then minimize this window and am back to my main window, I perform another search, a new window is populated and I open an application for Client "B", the session variables are overwritten so that Client "B's" information is now available.  If I return to Client "A's" window and hit a save button, it overwrites client "B's" information in the database as it updates based on the session variable of an application ID.  

I need to ensure that if a new client's application is opened, the previous one is closed so that it cannot overwirte the wrong client's information.  I am attaching some code, but I think the concept is the bigger picture, I may even be going about this in the wrong direction, any other suggestions would be of great help as well.  Sometimes the straight forward answer isn't the best one!
Main Page:
 
//search section
<tr>
                <td>
                <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="btnSearch" runat="server" Text="Search By FirmName" OnClientClick="Search()" OnClick="btnSearch_Click"  /></td>
            </tr>
 
 
JavaScript on main page:
function Search()
{
    
    <%=Page.GetPostBackEventReference(btnSearch as Control) %>
    
    window.open('/Pages/FirmSearch.aspx');
    
}
 
=====================================================
 
Codebehind for search button on aspx.cs page
protected void btnSearch_Click(object sender, EventArgs e)
        {
            Session["SearchText"] = null;
 
            Session["SearchText"] = txtSearch.Text.ToString() + "%";
            Session["searchText"].ToString();
        }
 
======================================================
 
 
Window with gridview:
 
<asp:GridView ID="gvFirmSearch" runat="server" AllowPaging="True" AutoGenerateColumns="False"
        CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
        Width="530px" OnSelectedIndexChanged="gvFirmSearch_SelectedIndexChanged" OnRowCommand="gvFirmSearch_RowCommand">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <RowStyle BackColor="#EFF3FB" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#2461BF" />
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:ButtonField DataTextField="firmname" HeaderText="Firm Name"  CommandName="OpenFirm" />
            <asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
            <asp:BoundField DataField="password" HeaderText="password" SortExpression="password" />
            <asp:ButtonField CommandName="OpenPIR" Text="Premium Indication" />
            <asp:ButtonField CommandName="OpenNewApp" Text="New App" />
        </Columns>
    </asp:GridView>
 
=======================================
codebehind for gridview click:
 
protected void gvFirmSearch_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string userid = gvFirmSearch.Rows[int.Parse(e.CommandArgument.ToString())].Cells[1].Text.ToString();
 
            e.CommandName.ToString();
            
 
            DataAccess.getClientIDByEmail(userid.ToString());
            DataAccess.getAppIDByClientID(Session["clientid"].ToString());
            Session["SignedIn"] = "1";
            
            if(e.CommandName.ToString() == "OpenPIR")
                Response.Redirect("/pages/PremiumIndication/PremiumIndication.aspx",false);
            else
	            if(e.CommandName.ToString() == "OpenNewApp")
                    Response.Redirect("/pages/NewApp/NewApp.aspx", false);
                else
                    if (e.CommandName.ToString() == "OpenFirm")
                        Response.Redirect("/pages/UserArea.aspx", false);
            
        }

Open in new window

0
Comment
Question by:attaylor44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:attaylor44
ID: 21849315
I would be pleased if the click of the search button closed any previous instance of an open window before opening a new window.... this would insure that no other client applcation/forms are open (we do not need to allow the end user to view multiple accounts at a single time).
0
 
LVL 7

Expert Comment

by:60MXG
ID: 21850711
Here is how I pass the parameter to other form in my applications which is written in asp.net with C#.  
--------------------------------- Main form ----------------------------------
<html>
        <script language="javascript">
              function selectIt(x)
                     {
                           var L= 350
                           if (screen.availHeight < 800)
                           L = 100;

                           var features = " ' top=10, left= " + 1 + ", width=860, height=640, resizable=yes ' "
                           var w=window.open("editApp.aspx?id=" + x, null);
                      }
        </script>
        <form>
              <table id="tblMain">
                    <tr>
                           <td width="5%"></td>
                           <td>
                                    <asp:datagrid id="dgMain" Runat="server" OnItemCreated="dgMain_ItemCreated" .....>  -- --------------------------------I didn't type in all the code here assuming you know ----------
                                          <Columns>
                                                <asp:TemplateColumn>
                                                     <ItemTemplate>
                                                           <input type="button" id="btnClick" value="View" onclick="selectIt('<%#DataBinder.Eval(Container.DataItem, "passingParameter")%>);">
                                                     </ItemTemplate>
                                                </asp:TemplateColumn>
                                          </Columns>
                                    </asp:datagrid>
                           </td>
                    </tr>
              </table>
          </form>
</html>

----------------------------------------- Main Form End Here ------------------------------------------



---------------------------------------- editApp.aspx form that accept the passing parameter --------------------
---------------------------------------- Only the code behide is shown here ------------------------------------------

using System;
using .....;
using ...;

name space Client.Data
{
        public class editApp : Client.Data
           {
                   public string tempId;  ------- this string is going to be used to capture passing parameter
                 
                   private void Page_Load(object sender, System.EventArgs e)
                   
                   tempId  = Request.QueryString["id"];           --- id  parameter pass from the javascript

                   if (tempId.ToString() == "")
                    {
                    }
                    else
                     {
                     }
            }
}

It seems much easier that way!
0
 

Author Comment

by:attaylor44
ID: 21854730
My initial thought was that a session variable would be more secure in that if the page loads based on a query string a user could simply type in www.host.com?id=12345 and get an application form to open.  We will have many users that can log in and I want to ensure that the user has been logged in and that the id they reference belongs to them, thus I didn't really want it to be passed in a query string... am I mistaken or overlooking things?

For the most part, I just want a button click event that checks to see if a window of name "my_window" has been opened, if it has been opened, I want the code to close it before opening it again with the new information.  If it is not currently open, I want to simply open a new instance of "my_window".  

With this idea, I can have a search field and button on FormA, the user clicks the button to search, it checks to see if a window is open (not just any window, but the window with a name, a child window... something like that) and if it is, close it to ensure that the user will NOT write over existing informaiton, set session variables to reference new documentID, and open a new window.

More or less, I need to know how to have a C# page open a window that it can mantain a reference to so that the button that generates this new page can check/colse the window it created.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:60MXG
ID: 21857340
           private void Page_Load(object sender, System.EventArgs e)
            {

                  if (!Page.IsPostBack)
                  {
                        Configuration.ConfigReader configReader = new ConfigReader();
                        base.SetSecurityContext(PrincipalConfig.UseSession);
                        RememberMeCookie.Write();

                        gUserProfile = new UserProfile(base.CurrentIdentity);
                        if (base.CurrentIdentity.IsAnonymous)
                        {
                              Response.Redirect("../../ManageProfile.asp");
                        }
                        else
                        {
                              base.SetSecurityContext(PrincipalConfig.UseSession);
                              RememberMeCookie.Write();
                              gUserProfile = new UserProfile(base.CurrentIdentity);
                              _MQTP = new MQTP(base.CurrentIdentity);
                              UserRecordCountMQTP = _MQTP.CheckMQTPUser();
                              if (UserRecordCountMQTP < 1)
                              {
                                    Response.Write("You do not have access to this application!");
                                    Response.End();
                              }
                              else
                              {
                                    PopulatedMQTPClass();
                                    ddlRank.Enabled = false;
                                    PopulatedSquadrons();
                                    PopulatedRank();
                                    PopulatedShift();
                              }

                        }


                  }
            }


Code the Session like I did here.  In this section of the code it shows the logic of how I handle the session.
0
 

Author Comment

by:attaylor44
ID: 21857414
After passing this by my manager, I was informed that querystrings are not a valid solution at this point. If it is found that there is no way to accomplish the open/close of a window via JavaScript management then we will revisit the querystring method.  Thank you for your suggestions.
0
 

Accepted Solution

by:
attaylor44 earned 0 total points
ID: 21869094
Anyone have more info on JavaScripting open/close window?
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question