Solved

Open small window on listbox SelectedIndexChanged

Posted on 2009-07-15
12
547 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

778 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