To open a new window in listitem of listbox

Last post 05-12-2008 2:19 AM by vvsprasad. 2 replies.

Sort Posts:

  • To open a new window in listitem of listbox

    05-09-2008, 7:47 AM
    • Loading...
    • vvsprasad
    • Joined on 05-09-2008, 5:06 AM
    • Posts 2

    Hi
    after double click of listitem in listbox a popwindow will open.i am able to get this using below code but when i clicked on another listitem.i am not able to get a popupwindow.after closing the previous one,able to get current selection.

    <script type="text/javascript" language="javascript">
    function display()
    {
    debugger;
    var list=window.document .getElementById ("ListBox1");
    var text=list.options[list.options.selectedIndex].text;
    var text1=list.options[list.options.selectedIndex].text;
    if(text==text1)

    window.open("addform.aspx","mypage","scrollbar=no,height=500,width=300,resize=0,menubar=0,location=0");
    }
    //page_load
    ListBox1.Attributes.Add("ondblclick", "javascript:display();");

  • Re: To open a new window in listitem of listbox

    05-09-2008, 10:33 AM
    • Loading...
    • NC01
    • Joined on 08-26-2005, 3:33 PM
    • Posts 6,886
    • TrustedFriends-MVPs

    I don't know what you're trying to do with the compare if(text==text1) since they will always be equal. You're comparing the same value every time. If you are trying to pass the selected value to a child window (or popup), try this:

    Parent.aspx:

    <form id="Form1" method="post" runat="server">
     <asp:listbox id="ListBox1" ondblclick="openWindow(this)" runat="server">
      <asp:listitem value="1">Item 1</asp:listitem>
      <asp:listitem value="2">Item 2</asp:listitem>
      <asp:listitem value="3">Item 3</asp:listitem>
      <asp:listitem value="4">Item 4</asp:listitem>
      <asp:listitem value="5">Item 5</asp:listitem>
      <asp:listitem value="6">Item 6</asp:listitem>
     </asp:listbox>
    </form>

    <script type="text/javascript">
    <!--
    function openWindow(elementRef)
    {
     var selectedIndex = elementRef.selectedIndex;
     var selectedValue = elementRef.options[selectedIndex].text;

     var windowUrl = 'Child.aspx?selectedValue=' + selectedValue;
     var windowName = 'Window_' + new Date().getTime();
     var windowFeatures =
      'channelmode=no,directories=no,fullscreen=no,' +
      'location=yes,dependent=yes,menubar=no,resizable=no,scrollbars=yes,' +
      'status=no,toolbar=no,titlebar=no,' +
      'left=0,top=0,width=500px,height=300px';

     window.open(windowUrl, windowName, windowFeatures);
    }
    // -->
    </script>

    Child.aspx.cs:

    private void Page_Load(object sender, System.EventArgs e)
    {
     string selectedValue = (this.Request["selectedValue"] == null) ? string.Empty : this.Request["selectedValue"];
     this.Response.Write("selectedValue [" + selectedValue + "]<br>");
    }

    NC...

     

  • Re: To open a new window in listitem of listbox

    05-12-2008, 2:19 AM
    Answer
    • Loading...
    • vvsprasad
    • Joined on 05-09-2008, 5:06 AM
    • Posts 2

    Thank you very much i got the solution

Page 1 of 1 (3 items)