Referencing Values in a User Control

Last post 05-09-2008 7:27 AM by digvijay.chauhan. 5 replies.

Sort Posts:

  • Referencing Values in a User Control

    05-08-2008, 3:16 PM
    • Loading...
    • evanburen
    • Joined on 06-17-2002, 7:20 PM
    • Vancouver, BC
    • Posts 116

    Hi

    I'm clueless when it comes to user controls.  I have a control named header which contains 3 textboxes.  How do I grab the text entered in the textbox named txtCompanyName found in the control in my aspx page?

     

    My user control: header.ascx

    <%@ Control Language="VB" ClassName="header" %>

    <script runat="server">
        Protected Sub QuickSearch_Companies_Click(ByVal Sender As Object, ByVal e As EventArgs)
            Dim strCompanyName As String = txtCompanyName.Text
           
            'Take the text entered into the search form and send them to the search form
            Response.Redirect("quick.search.results.company.aspx?CompanyName=" & strCompanyName)
        End Sub
       
        Protected Sub QuickSearch_Candidate_Click(ByVal Sender As Object, ByVal e As EventArgs)
            Dim strFirstName As String = txtFirstName.Text
            Dim strLastName As String = txtLastName.Text
       
            'Take the text entered into the search form and send them to the search form
            Response.Redirect("quick.search.results.candidate.aspx?FirstName=" & strFirstName & "&LastName=" & strLastName)
        End Sub  
       

    </script>
            

    <table width="100%" border="0" cellpadding="3" cellspacing="0">

    <tr>
        <td> Company: <asp:Textbox ID="txtCompanyName" runat="server" CssClass="textbox" /></td>
        <td>Candidate Name: <asp:TextBox ID="txtFirstName" runat="server" CssClass="textbox" Columns="15" /> <asp:TextBox ID="txtLastName" runat="server" CssClass="textbox" Columns="15" Text="Last Name" /><asp:Button ID="btnCandidateSearch" runat="server" Text="go" CssClass="buttons" OnClick="QuickSearch_Candidate_Click" /></td>  
    </tr>   
    </table>


    .aspx page


    <%@ Page Language="VB" %>
    <%@ Register Src="header.ascx" TagName="header" TagPrefix="uc1" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>

    <script runat="server">

    'This fails
    Dim CompanyName As String = txtCompanyName.Text

    </script>


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Candidate Search</title>   
    </head>
    <body>

    <form id="form1" runat="server">
      
    <!--This is my user control page header-->
    <uc1:header id="Header1" runat="server"></uc1:header>

    </form>

     

     

     

  • Re: Referencing Values in a User Control

    05-08-2008, 3:29 PM

    Create public properties in the control that expose the textbox values you want to grab.
    If this answered your question, be sure to mark it as the answer. That way, everybody after you will know it's the answer also!
  • Re: Referencing Values in a User Control

    05-08-2008, 3:30 PM

     Check this post -

    http://www.dotnetjunkies.ddj.com/Article/E1F97CE9-7834-46FA-BED9-866F720AB013.dcik

    hope it helps. 

    Hope it helps.

    -Manas
  • Re: Referencing Values in a User Control

    05-08-2008, 3:52 PM
    • Loading...
    • evanburen
    • Joined on 06-17-2002, 7:20 PM
    • Vancouver, BC
    • Posts 116

    Thanks

    Is this also an accepted way of doing it?

    Dim CompanyName As Textbox=CType(Page.FindControl("Header1$txtCompanyName"),Textbox)

    Dim CompanyNameText As String = CompanyName.Text

     

     

  • Re: Referencing Values in a User Control

    05-09-2008, 6:50 AM

    I don't do VB very much, but it looks plausible.

    But I think that Header1.CompanyName (where CompanyName is a string) is a lot easier to code than your way. :) 

    If this answered your question, be sure to mark it as the answer. That way, everybody after you will know it's the answer also!
  • Re: Referencing Values in a User Control

    05-09-2008, 7:27 AM

     

    <script runat="server">

    'This fails
    Dim CompanyName As String = txtCompanyName.Text

    </script>

     

    Should not the statement be in a function or property ???

    Regards,

    Digvijay
    http://www.digvijay.eu
    http://blog.digvijay.eu

    --------
    Please remember to Mark As Answer if this post answered your question!
Page 1 of 1 (6 items)