Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open small window on listbox SelectedIndexChanged

Posted on 2009-07-15
12
Medium Priority
?
571 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:Kelvin McDaniel
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Expert Comment

by:Kelvin McDaniel
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:Kelvin McDaniel
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:
Kelvin McDaniel earned 1600 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:Kelvin McDaniel
ID: 24872354
Excellent... Congratuluations!

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 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