Solved

Open small window on listbox SelectedIndexChanged

Posted on 2009-07-15
12
557 Views
Last Modified: 2012-05-07
What I would liek to do is upon picking an item from a listbox is for a small window to open up telling information about what was picked.  For the information it can be done within the page3 behind by passing a caouple variables to it or I can pass all the variables to it, whatever way is easier for coding.  But the big question is first.  How can I make a window open from a listbox
SelectedIndexChanged  that is smaller than original page and can be clodes when they are done viewing the information.  I would prefer all vb.net 1.1 ways but will look at javascript if its easy to pass either a couple variables or maybe lots of variables to page.
0
Comment
Question by:kdeutsch
[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
  • 7
  • 5
12 Comments
 
LVL 11

Expert Comment

by:azarc3
ID: 24862673
The only browser-indepent and browser-safe way to open a physically separate window and control the window's size is to use JavaScript. Unfortunately, these are subject to the end-user's preference for pop-up windows.

The JavaScript code is very easy... it's simply

function_name (optional_variables)
{
    window.open("url_to_open_relative_or_absolute", "new_window_name"[, "window_features"]);
    return false; // this can be in the calling function, rather than here
}

If you want to use them, here's a list of window attributes you can set... I assume you'll want to use at least the window width and height, and probably the positioning.

status:  The status bar at the bottom of the window.
toolbar:  The standard browser toolbar, with buttons such as Back and Forward.
location:  The Location entry field where you enter the URL.
menubar:  The menu bar of the window
directories:  The standard browser directory buttons, such as What's New and What's Cool
resizable:  Allow/Disallow the user to resize the window.
scrollbars:  Enable the scrollbars if the document is bigger than the window
height:  Specifies the height of the window in pixels. (example: height='350')
width:  Specifies the width of the window in pixels.

* list taken from http://www.javascript-coder.com/window-popup/javascript-window-open.phtml . There's a good tutorial there also.

You can also open DHTML "windows" that won't be blocked... You can do these by hand or use some other 3rd party tool that generates the code for you at design time.
0
 

Author Comment

by:kdeutsch
ID: 24863274
azarc3:
Now this is for calling a standard asp.net page with javascript.  i need to put information on the page and send it two variables via the hyperlink if this is the case.  I need it to run 2 sql select scripts and show results on the page.
0
 

Author Comment

by:kdeutsch
ID: 24863292
How would I call this function from my code behind page as part of my listbox selectedIdexchanged event.
0
Industry Leaders: 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 11

Expert Comment

by:azarc3
ID: 24863360
No problem; you can pass query-string variables just like with any link.  :)

Once you get spawn the new window it behaves just like any other page request.
<script type="text/javascript">
function_name (variabl1,variable2)
{
    window.open("url_to_open_relative_or_absolute?v1=" + variable1 + "&v2=" + variable2 + ", "new_window_name"[, "window_features"]);
    return false; // this can be in the calling function, rather than here
}
</script>
 
// the rendered in-page code would like something like... You'll probably want to verify the syntax
<a href="#" onClick="function_name(variable1_value,variable2_value); return false;">my link</a>

Open in new window

0
 
LVL 11

Expert Comment

by:azarc3
ID: 24863674
Sorry; didn't see your followup...

Assuming that you've got the javascript function in the <HEAD></HEAD> area of your HTML code already... your SelectedIndexChanged() method content should look something like this... (assumes VS 2005 versions of VB and C#)...

VB Code:
------------------------------------------------
Dim jsString As String = "<script type=""text/javascript"">function_name({0},{1});</script>"
Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "JS_OpenWindow", String.Format(jsString, ListBox1.SelectedValue, variable2_value))
 
 
C# Code:
------------------------------------------------
string jsString = "<script type=""text/javascript"">function_name({0},{1});</script>";
Page.ClientScript.RegisterClientScriptBlock(Page.GetType, "JS_OpenWindow", String.Format(jsString, ListBox1.SelectedValue, variable2_value));

Open in new window

0
 

Author Comment

by:kdeutsch
ID: 24868717
Hi,
Still using vb.net with asp.net 1.1 (dark ages)
anyway I got something like the follwoing to work, but it has one big problem in that it always opens when you don't want it too and I am trying to figure out how to put in multiple variables to request string.
But it allows me to call out my page width and height and values from left and top.

 lbljavascript.Text = "<script language=javascript>window.open('PersonnelInfo.aspx?id=" & Id & "',SSN=" & Items(2) & "', '', 'width=800 height=600 top=absolute left=150');</script>"
0
 

Author Comment

by:kdeutsch
ID: 24868761
When I paste this into my   <Head></head> in HTML is blackens out for some reason.

<script language="javascript">
function_name (variabl1,variable2)
{
window.open("Personnel.aspx?v1=" + variable1 + "&v2=" + variable2 + ", "new_window_name"[, "window_features"]);
return false;
}
</script>

How do I get the variables using javascript, sorry do not a lot about javascript, i use sparringly.
0
 
LVL 11

Accepted Solution

by:
azarc3 earned 400 total points
ID: 24869094
No problem; I understand your pain. ;)

Not sure why it's blacking out on you... I've mocked up (and tested, it works fine) an example that should get you going. Make sure you take the ".txt" off the file extentions inside the archive.
js-opener-example.zip
0
 

Author Comment

by:kdeutsch
ID: 24869736
Hi,
Ok here is what I changed to but I get a Javascript error of error invalid argument and it calls out the script line I put in.

<script language="javascript">
      function ShowItemDetail(Id,SSN)
      {
      opener = window.open("PersonneLInfo.aspx?id=" + Id + "&SSN=" + SSN, "width=800,height=600,scrolling=no");
      return false;
      }
      </script>

here is the code behind
        Dim Id As String = lblHiddenId.Text
        Dim SSN As String = lbPersonnel.SelectedValue
        Dim litShowItem As New Literal
        litShowItem.Text = "<script type=""text/javascript"">ShowItemDetail(" & Id & "," & SSN & ");</script>"
        PlaceHolder1.Controls.Add(litShowItem)

0
 

Author Comment

by:kdeutsch
ID: 24872092
Hi,
got it done , here are the final parts for asp.net 1.1
HTML
<script language="javascript">
      function ShowItemDetail(Id,SSN)
      {                        
      window.open("PersonnelInfo.aspx?id=" + Id + "&SSN=" + SSN, "", "width=800 height=600 Top=Absolute left=180 scrolling=no");                        
      }
      </script>

<body>
<asp:placeholder id="placeholder1" runat="server"></asp:placeholder>
</body>

Code Behind in listbox change event
        Dim Id As String = lblHiddenId.Text
        Dim SSN As String = lbSoldier.SelectedValue
        Dim litShowItem As New Literal
        litShowItem.Text = "<script type=""text/javascript"">ShowItemDetail(" & Id & "," & SSN & ");</script>"
        PlaceHolder1.Controls.Add(litShowItem)
0
 

Author Closing Comment

by:kdeutsch
ID: 31603852
Thanks for the help, way better solution than I was originally using.
0
 
LVL 11

Expert Comment

by:azarc3
ID: 24872354
Excellent... Congratuluations!

Sorry about the delay; I've been away at meetings. Glad you got it going.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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