getting listbox selected value in client side

6 posts, 0 answers
  1. Webster Velasco
    Webster Velasco avatar
    114 posts
    Member since:
    Jun 2012

    Posted 25 Nov 2009 Link to this post

    hello

    im new here in telerik and i will appreciate any kind of help..
    here is my problem:
     from my Main.aspx   i open a RadWindow which contain a listbox.. from that listbox i want to get as return value the selected  value of that webcontrol and put it in my Main.aspx txtbox..

    can someone please post the code for my problem?

    thanks in advance.
    regards webster.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Nov 2009 Link to this post

    Hello,

    Here is the code that I tried for the same scenario. Get the selected item of RadListBox in DialogPage and pass the value as argument on closing the window. And you can access the argument in the OnClientClose event of RadWindow in MainPage.

    MainPage.aspx:
     
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" OnClientClose="OnClientClose"
            <Windows> 
                <telerik:RadWindow runat="server" VisibleOnPageLoad="true" Behavior="Default" InitialBehavior="None" 
                    Left="" NavigateUrl="Dialog1.aspx" Top=""
                </telerik:RadWindow> 
            </Windows> 
        </telerik:RadWindowManager> 
     
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 

    jscript:
     
    <script type="text/javascript"
        function OnClientClose(sender, args) { 
            if (args.get_argument() != null) { 
                document.getElementById("TextBox1").value = args.get_argument() 
            } 
        } 
    </script> 

    DialogPage.aspx:
     
    <telerik:RadListBox ID="RadListBox1" runat="server"
        <Items> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem1" /> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem2" /> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem3" /> 
        </Items> 
    </telerik:RadListBox> 
    <input id="Button1" type="button" value="Close" onclick="closeWindow();" /> 

    jscript:
     
    <script type="text/javascript"
        function closeWindow() { 
            var listbox = $find("<%= RadListBox1.ClientID %>"); 
            var sel = listbox.get_selectedItem().get_value(); 
            debugger
            var oWnd = GetRadWindow(); 
            oWnd.close(sel); 
        } 
        function GetRadWindow() { 
            var oWindow = null
            if (window.radWindow) 
                oWindow = window.radWindow; 
            else if (window.frameElement.radWindow) 
                oWindow = window.frameElement.radWindow; 
            return oWindow; 
        }   
    </script> 

    Check the following help document which shows most important cluient side methods ofRadListBox.
    RadListBox client API

    Also checkout the following links which demonstrates how to pass the values from dialod window.
    Returning Values from a Dialog (Demo)
    Using RadWindow as a Dialog (Documentation)

    Hope this helps,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Webster Velasco
    Webster Velasco avatar
    114 posts
    Member since:
    Jun 2012

    Posted 26 Nov 2009 Link to this post

    i try this thanks..
  5. Webster Velasco
    Webster Velasco avatar
    114 posts
    Member since:
    Jun 2012

    Posted 26 Nov 2009 Link to this post

    its seems not to work..
    BTW i use .datasource to populate my listbox and use telerik txtbox as my selected value container from my main page.. here is dialog and main page code..

    main page:
        <script type="text/javascript">  
            function closeWindow() {  
                var listbox = $find("<%= lstCodiceLingue.ClientID %>");  
                var sel = listbox.get_selectedItem().get_value();  
                debugger;  
                var oWnd = GetRadWindow();  
                oWnd.close(sel);  
            }  
            function GetRadWindow() {  
                var oWindow = null;  
                if (window.radWindow)  
                    oWindow = window.radWindow;  
                else if (window.frameElement.radWindow)  
                    oWindow = window.frameElement.radWindow;  
                return oWindow;  
            }    
        </script> 
          
        <form id="form1" runat="server"
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
            <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" /> 
        <div> 
            <telerik:RadListBox ID="lstCodiceLingue" runat="server"
            </telerik:RadListBox> 
            <button title="Submit" id="close" onclick="closeWindow();">Submit</button><telerik:RadComboBox 
                ID="RadComboBox1" runat="server"
            </telerik:RadComboBox> 
        </div> 
        </form> 

    dialog
      <div style="height:500px"
          <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
          <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" /> 
            
           <script type="text/javascript"
                function OpenWin() 
                { 
                    var oWnd = radopen("Zoom.aspx", "rdwCodiceLingue"); 
                } 
                function OnClientClose(sender, args) {  
                    if (args.get_argument() != null) {  
                        document.getElementById("txtCODICELINGUE").value = args.get_argument()  
                    }  
                }  
                 
           </script> 
              
          <telerik:RadWindowManager ID="RadWindowManager1" runat="server" ShowContentDuringLoad="false" VisibleStatusbar="false" ReloadOnShow="true"
            <Windows> 
                <telerik:RadWindow ID="rdwCodiceLingue" runat="server" Behaviors="Close" OnClientClose="OnClientClose" NavigateUrl="Zoom.aspx"></telerik:RadWindow> 
            </Windows> 
          </telerik:RadWindowManager> 
          <table> 
                <tr> 
                <td> 
                    <button onclick="OpenWin(); return false;">Open</button> 
                    <asp:textbox ID="txtCODICELINGUE" runat="server" /> 
                </td> 
                </tr> 
          </table> 
      </div> 
     

    P.S. my mainpage is on a contenplaceholder control
  6. Webster Velasco
    Webster Velasco avatar
    114 posts
    Member since:
    Jun 2012

    Posted 26 Nov 2009 Link to this post

    probem fixed.. thanks
  7. surya
    surya avatar
    9 posts
    Member since:
    Dec 2015

    Posted 19 Jan Link to this post

    Hello Telerik team..

    i have a requirment  to display selected item from radlistbox in textbox.

     i can see the value in alert window but it is not displaying in the textbox.could you please help me out...

    P.S:I am using radlistbox and rad textbox.

    function lstselectindexchanged(sender, e) {
              var listbox = $find("<%=lstStoreRegisters.ClientID %>");
                var sel = listbox.get_selectedItem().get_value();
                //alert(sel);
                var textbox = $find("<%=txtRename.ClientID %>");
                //alert(textbox);
                textbox.value = sel;
                //textbox.text = sel;
                //alert(textbox.value);
                
            }

     

     

    Thanks

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017