This is a migrated thread and some comments may be shown as answers.

getting listbox selected value in client side

5 Answers 1104 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Webster Velasco
Top achievements
Rank 2
Webster Velasco asked on 25 Nov 2009, 05:24 PM
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.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Nov 2009, 06:56 AM
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.
0
Webster Velasco
Top achievements
Rank 2
answered on 26 Nov 2009, 08:34 AM
i try this thanks..
0
Webster Velasco
Top achievements
Rank 2
answered on 26 Nov 2009, 08:56 AM
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
0
Webster Velasco
Top achievements
Rank 2
answered on 26 Nov 2009, 02:38 PM
probem fixed.. thanks
0
surya
Top achievements
Rank 1
answered on 19 Jan 2016, 07:56 PM

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

Tags
ListBox
Asked by
Webster Velasco
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Webster Velasco
Top achievements
Rank 2
surya
Top achievements
Rank 1
Share this question
or