RadComboBox Postback Question

2 posts, 0 answers
  1. dino
    dino avatar
    15 posts
    Member since:
    Jul 2012

    Posted 23 Oct 2012 Link to this post

    I'm trying to do a database lookup based on what the user selects from the radcombobox.  The SelectedIndexChanged event isn't firing. Well, actually, it does fire but I'm not seeing the result of the postback (textbox.text = result) until I change a different field on the form (RadTextBox field). When I change the value of that field the TextChanged event runs and does what it's supposed to and I can then see the result of the SelectedIndexChange event from the combobox.


    MARKUP
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="reg.aspx.vb" Inherits="TelerikWebForm" MasterPageFile="~/masterpage.master" maintainScrollPositionOnPostback = "true" %>
    <asp:Content id="content1" ContentPlaceHolderID="cph_content" runat="server">
     
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <%--Needed for JavaScript IntelliSense in VS2010--%>
                <%--For VS2008 replace RadScriptManager with ScriptManager--%>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
     
        <telerik:RadSkinManager ID="RadSkinManager1" Runat="server" Skin="Web20">
        </telerik:RadSkinManager>
        <div id="main">
            <div id="content">
            
                <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Width="680px" LoadingPanelID="RadAjaxLoadingPanel1">
                <!--COMPANY / ISSUE-->
                <telerik:RadComboBox ID="RadComboBox1"
                    Label="Name of Stock: "
                    runat="server"
                    Width="300px"
                    LabelWidth="133px" 
                    Height="150px"
                    EmptyMessage="Enter Name of Company whose stock you own"
                    DataSourceID="sqldatasource1"
                    DataTextField="coname"
                    DataValueField="issuenum"
                    EnableAutomaticLoadOnDemand="True"
                    ShowMoreResultsBox="true"
                    EnableVirtualScrolling="True"
                    OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"
                    AllowCustomText="false"
                    LoadingMessage="Searching..."
                    MinFilterLength="0"
                    AutoPostBack="true">
                    </telerik:RadComboBox>
                 
                    <asp:Label ID="lblConameLookup" runat="server" Text=" " Width="275" CssClass="label1" Visible="true"></asp:Label>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="Name of Stock is required." ControlToValidate="RadComboBox1" CssClass="label1error"></asp:RequiredFieldValidator>
                     
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server"  ConnectionString="..."></asp:SqlDataSource>
                <br />
     
                 
                <!--USERNAME-->
                <telerik:RadTextBox ID="txtUsername" runat="server" Label="Username:" EmptyMessage="30 character max" MaxLength="30" LabelWidth="130" Width="300" OnTextChanged="txtUsername_TextChanged" AutoPostBack="true">
                </telerik:RadTextBox>
                <img alt="Info" src="/images/icon_info.png" title="Username Rules: 8 - 30 characters in length; can only contain the following: A-Z, a-z, 0-9, ! @ . _ - " class="infoicon" />
                <asp:Label ID="lblUsernameValidatorMsg" runat="server" Text=" " CssClass="label1error" Visible="false"></asp:Label>
                <asp:TextBox ID="txtUsernameValidatorStatus" visible="false" Text="Invalid" runat="server"></asp:TextBox>
                </telerik:RadAjaxPanel>
     
     
                <!--BUTTONS-->
                <telerik:RadButton ID="RadButton1" runat="server" Text="Submit" CausesValidation="true" >
                    </telerik:RadButton>
     
             
            <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" >
        </telerik:RadAjaxLoadingPanel>
            
        </div></div>
     
        <telerik:RadToolTipManager ID="RadToolTipManager1" runat="server" RelativeTo="Element"
                Position="MiddleRight" AutoTooltipify="true" ContentScrolling="Default" Width="225"
                Height="10" AutoCloseDelay="10000">
            </telerik:RadToolTipManager>
     
    </asp:Content>



    Protected Sub RadComboBox1_SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged
     
            Dim strConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("CONN").ConnectionString
            Dim MySQL As String = "SELECT ticker FROM [table] WHERE [issuenum] = @issuenum"
     
            Dim MyConn As New Data.SqlClient.SqlConnection(strConn)
            Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, MyConn)
            Dim DR As SqlDataReader
     
            With Cmd.Parameters
                .Add(New SqlClient.SqlParameter("@issuenum", UCase(Trim(RadComboBox1.SelectedValue))))
            End With
     
            lblConameLookup.Visible = True
            Try
                MyConn.Open()
                DR = Cmd.ExecuteReader()
                DR.Read()
                lblConameLookup.CssClass = "label1"
                lblConameLookup.Text = DR("ticker")
            Catch ex As Exception
                lblConameLookup.CssClass = "label1error"
                lblConameLookup.Text = "Please select a company from the dropdown menu."
            End Try
            MyConn.Close()
     
        End Sub
     
     
        'VALIDATION FOR USERNAME FIELD
        Protected Sub txtUsername_TextChanged(sender As Object, e As System.EventArgs) Handles txtUsername.TextChanged
           
            'CHECK DATABASE
            Dim strConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("CONN").ConnectionString
            Dim MySQL As String = "SELECT X1,X2 FROM Ytable WHERE [field] = @param"
     
            Dim MyConn As New Data.SqlClient.SqlConnection(strConn)
            Dim Cmd As New Data.SqlClient.SqlCommand(MySQL, MyConn)
            Dim DR As SqlDataReader
     
            With Cmd.Parameters
                .Add(New SqlClient.SqlParameter("@param", Trim(txtUsername.Text)))
            End With
     
            Try
                MyConn.Open()
                DR = Cmd.ExecuteReader()
                DR.Read()
                lblUsernameValidatorMsg.Visible = True
                If DR.HasRows = True Then
                    lblUsernameValidatorMsg.Text = "This username is unavailable."
                    txtUsername.Focus()
                End If
            Catch ex As Exception
                'lblUserNameStatus.Text = ex.Message
            End Try
            MyConn.Close()
        End Sub


    I omitted some of the fields on the input form for simplicity and changed some of the SQL.  I may have some unmatching divs and stuff like that but you can ignore it.

    Any help would be greatly appreciated.

    Thanks.
  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 29 Oct 2012 Link to this post

    Hello dino,

    I created a sample page using your code and inspected RadComboBox behaviour - on my side the control raises SelectedIndexChanged as expected.
    Please find the sample attached and give it a try.
    I suppose that there is something specific in your implementation that causes the issue.

    All the best,
    Kalina
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top