1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / User control button click not firing

User control button click not firing

4 posts, 0 answered
  1. Jeffrey Monroe
    Jeffrey Monroe avatar
    2 posts
    Registered:
    12 Feb 2010
    16 Feb 2010
    Link to this post
    Hello,
         I am hoping that someone here can assist me. I have created a 2 simple custom user controls, a search tool and a search results tool.. The problem is that the "search" button click event is only captured every other time it is clicked no matter what I try. I have searched the forums and the Internet, and found a couple of threads about similar issues, but none of the fixes are working for me.  The Page_Load is firing every time the button is clicked, but the button_click event is only being called every other time.  I appreciate any assistance anyone can offer.  I am using Windows 7 64bit on my development machine. Below is the code for my user controls:

    MedicalProviderSearch.ascx:

    01.<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MedicalProviderSearch.ascx.vb" Inherits="UserControls_MedicalProviderSearch" %>
    02.<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
    03.<%@ Reference Control="~/UserControls/MedicalProviderSearchResults.ascx" %>
    04. 
    05.<div
    06.    id="divProviderSearch">
    07. 
    08.    <asp:Panel
    09.        ID="pnlProviderSearch"
    10.        runat="server"
    11.        DefaultButton="btnPerformSearch">
    12.         
    13.        <asp:Label
    14.            ID="lblProviderSearch"
    15.            runat="server"
    16.            Text="Find a Provider">
    17.        </asp:Label>
    18.         
    19.        <br /><br />
    20.                 
    21.        <asp:Label
    22.            ID="lblTxtSearchTerm"
    23.            runat="server"
    24.            AssociatedControlID="txtSearchTerm"
    25.            Font-Size="Small"
    26.            Text="Name:"> </asp:Label>
    27.         
    28.        <ajax:TextBoxWatermarkExtender
    29.            ID="wmkTxtSearchTerm"
    30.            runat="server"
    31.            Enabled="true"
    32.            TargetControlID="txtSearchTerm"            
    33.            WatermarkText="Enter Name Here">
    34.        </ajax:TextBoxWatermarkExtender>
    35.         
    36.        <br />
    37.         
    38.        <asp:TextBox
    39.            ID="txtSearchTerm"
    40.            runat="server"
    41.            MaxLength="50"></asp:TextBox>
    42.         
    43.        <br /><br />
    44. 
    45.        <asp:Label
    46.            ID="lblDrpSpecialty"
    47.            runat="server"
    48.            AssociatedControlID="drpSpecialty"
    49.            Font-Size="Small"
    50.            Text="Specialty:"> </asp:Label>
    51.         
    52.        <asp:SqlDataSource ID="srcProviderCategories"
    53.            runat="server"
    54.            ConnectionString="<%$ ConnectionStrings:Sitefinity %>"
    55.            SelectCommand="_Load_Categories"
    56.            SelectCommandType="StoredProcedure">
    57.        </asp:SqlDataSource>
    58.         
    59.        <br />
    60.         
    61.        <asp:DropDownList
    62.            ID="drpSpecialty"
    63.            runat="server"
    64.            DataSourceID="srcProviderCategories"
    65.            DataTextField="Cat_name"
    66.            DataValueField="Cat_id"
    67.            DataMember="DefaultView">
    68.        </asp:DropDownList>
    69.         
    70.        <br /><br />
    71.               
    72.        <asp:Button
    73.            ID="btnPerformSearch"
    74.            runat="server"
    75.            Text="Search"
    76.            Width="100px" />
    77.         
    78.    </asp:Panel>
    79. 
    80.</div>

    MedicalProviderSearch.ascx.vb:

    01.Imports System
    02.Imports Telerik
    03.Imports System.Data.SqlClient
    04.Imports UserControls_MedicalProviderSearchResults
    05. 
    06.Partial Class UserControls_MedicalProviderSearch
    07.    Inherits System.Web.UI.UserControl
    08. 
    09.    Protected Sub Initiate_Search()
    10. 
    11.        Dim ctrl As UserControls_MedicalProviderSearchResults
    12. 
    13.        If "/MedicalCMS/ProviderSearchResults.aspx" <> Request.Path Then
    14.            Response.Redirect("http://localhost/MedicalCMS/ProviderSearchResults.aspx")
    15.        Else
    16.            ctrl = Me.NamingContainer.NamingContainer.Controls(4).Controls(5).Controls(0)
    17.            ctrl.Locate_Provider(Session("name"), Session("sp"))
    18.            Session("locate") = Nothing
    19.        End If
    20. 
    21.    End Sub
    22. 
    23.    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    24. 
    25.        If Not IsNothing(Session("locate")) Then
    26.            Initiate_Search()
    27.        End If
    28. 
    29.    End Sub
    30. 
    31.    Protected Sub btnPerformSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPerformSearch.Click
    32. 
    33.        Session("name") = Trim(txtSearchTerm.Text)
    34.        Session("sp") = drpSpecialty.SelectedValue
    35.        Session("locate") = True
    36.        Initiate_Search()
    37. 
    38.    End Sub
    39. 
    40.End Class

    MedicalProviderSearchResults.ascx:

    01.<%@ Control Language="VB" AutoEventWireup="false" CodeFile="MedicalProviderSearchResults.ascx.vb" Inherits="UserControls_MedicalProviderSearchResults" %>
    02. 
    03. 
    04.<div  
    05.    id="divProviderSearchResults">
    06.     
    07.    <asp:Panel
    08.        ID="pnlProviderSearchResults"
    09.        runat="server">       
    10.         
    11.    </asp:Panel>
    12.     
    13.</div>

    MedicalProviderSearch.ascx.vb:

    01.Imports System
    02.Imports System.Data.SqlClient
    03.Imports System.Data
    04. 
    05.Partial Class UserControls_MedicalProviderSearchResults
    06.    Inherits System.Web.UI.UserControl
    07. 
    08.    Public Sub Locate_Provider(ByVal strName As String, ByVal intSpecialty As Integer)
    09. 
    10.        Dim litInfo As Literal
    11.        Dim lnkBtn As LinkButton
    12.        Dim dtProviders As DataTable = New DataTable()
    13.        Dim sqlData As SqlDataAdapter = New SqlDataAdapter()
    14.        Dim sqlConn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("Sitefinity").ConnectionString)
    15. 
    16.        sqlData.SelectCommand = New SqlCommand()
    17.        sqlData.SelectCommand.Connection = sqlConn
    18.        sqlData.SelectCommand.CommandText = "_Locate_Provider"
    19.        sqlData.SelectCommand.CommandType = CommandType.StoredProcedure
    20.        sqlData.SelectCommand.Parameters.Add("@Name", SqlDbType.NVarChar, 250).Value = strName
    21.        sqlData.SelectCommand.Parameters.Add("@Specialty", SqlDbType.Int).Value = intSpecialty
    22.        sqlData.Fill(dtProviders)
    23. 
    24.        For Each dRow As DataRow In dtProviders.Rows
    25. 
    26.            lnkBtn = New LinkButton()
    27.            lnkBtn.Text = dRow("Provider_fname") & " " & dRow("Provider_lname")
    28.            lnkBtn.PostBackUrl = "http://localhost/MedicalCMS/Main/ProviderBio.aspx" & "?id=" & dRow("Provider_id")
    29.            pnlProviderSearchResults.Controls.Add(lnkBtn)
    30. 
    31.            litInfo = New Literal()
    32.            litInfo.Text = ", " & dRow("Cat_name") & "<br /> " & dRow("Location_street") _
    33.            & " in " & dRow("Location_city") & ", " & dRow("Location_state") & " (" & dRow("Location_hours") _
    34.            & ")<br /><br />"
    35.            pnlProviderSearchResults.Controls.Add(litInfo)
    36. 
    37.        Next
    38. 
    39.    End Sub
    40. 
    41.End Class

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Feb 2010
    Link to this post
    Hello Jeffrey Monroe,

    In your code I could not find where you have subscribed for the Click event of the button. You can do it on Page_Load.

    btnPerformSearch.Click += new EventHandler(btnPerformSearch_Click);

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Jeffrey Monroe
    Jeffrey Monroe avatar
    2 posts
    Registered:
    12 Feb 2010
    17 Feb 2010
    Link to this post
    Ivan,
         Thank you for your prompt reply.  I believe that line# 31 in the file contains the  

    Handles btnPerformSearch.Click

    which is required for VB to associate the command with the control.
    Per your suggestion, I did try adding the following:

    AddHandler btnPerformSearch.Click, AddressOf btnPerformSearch_Click

    which resulted in the btnPerformSearch_click code being ran twice when the event fired, but the event still only fired every other time the button was pressed. 

    The problem is that the button click event is only firing every other time the button is pressed, and I can't figure out why.  I appreciate any help that you can offer. 

         Thank you,
         Jeffrey Monroe
  4. Eliza Sahoo
    Eliza Sahoo avatar
    5 posts
    Registered:
    25 Jan 2010
    30 Mar 2010
    Link to this post
    Problem
    If we are using watermark extender in a textbox, and also are trying to set the value of TextBox using JavaScript or jQuery, the text takes the format of watermarkCssClass style of that watermark extender .
    e.g:
    $('#textboxId').val("My Text"); 

    For instance, if we set the watermark style as italic and color as gray , the text is always shown in gray italic and also behaves like a watermark text.
    Solution
    Call get_Text and set_Text methods of TextBoxWatermarkExtenderto support client-side script access to the text in a watermarked text box.
    Implementation

    Lets take a text box with id "txtCity" 
    And watermarkExtender whose id is : “watermarkExTxtCity” , target id is : “txtCity” , behaviour id is : “behTxtCity” , watermark text= “Select City”
     

    Now inside the script tag :
    <script type="text/javascript" >
       -
       -
       //Find the watermark extender using behaviour id refers to city text box
       $find("behTxtCity" ).set_Text("My Text" ); 
     
       //Similarly we can use get_Text() to take the value .
       -
       -
       -
    </script>
    Hope it did add value.Any suggestions are welcomed.
Register for webinar
4 posts, 0 answered