Solved

Open small window on listbox SelectedIndexChanged

Posted on 2009-07-15
12
540 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
Comment Utility
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
Comment Utility
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
Comment Utility
How would I call this function from my code behind page as part of my listbox selectedIdexchanged event.
0
 
LVL 11

Expert Comment

by:azarc3
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:kdeutsch
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for the help, way better solution than I was originally using.
0
 
LVL 11

Expert Comment

by:azarc3
Comment Utility
Excellent... Congratuluations!

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now