Results 1 to 3 of 3

Thread: User Control

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    62

    User Control

    I have created a user control which is basically just like the include file in the old asp code.
    userform.ascx looks like this
    Code:
    <%@ Control Language="c#" AutoEventWireup="false" Codebehind="userform.ascx.cs" Inherits="user.userform" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
    <TR>
      <td><font color="red" size="bold">*</font> User Name</td>
      <td><asp:textbox id="userName" MaxLength="50" 
                      Runat="server"></asp:textbox></td>
    </TR>
    <TR>
      <td><font color="red" size="bold">*</font> Password</td>
      <td><asp:textbox id="password" MaxLength="50" Runat="server" TextMode="Password"></asp:textbox></td>
    </TR>
    mainpage.aspx looks like this. To save space, I have just put the code that is linked to this question:
    Code:
    <%@ Reference Control="userform.ascx" %>
    .
    .
    .
    .
    </tr>
    <asp:PlaceHolder id="userHolder" Runat="server"></asp:PlaceHolder>
    <tr>
    .
    .
    .
    In the userform.ascx.cs Page_Load routine I have the following code:

    Code:
    Control UserInfo = LoadControl("userform.ascx");
    userHolder.Controls.Add(UserInfo);
    Now how can I check what the value of user name and password is from the main.aspx? Thanks in advance

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: User Control

    Have you tried:

    UserInfo.userName.Text

    I haven't tested that, but its worth a shot. If thats not correct, there is probably another property or method you can use and just pass it the name of the control you are looking for.
    ~Ryan





    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2004
    Posts
    62

    Resolved Re: User Control

    I was able to get the solution I wanted:
    Here is what I did:
    In the
    mainpage.aspx, I change the code to look like this:
    Code:
    <%@ Register TagPrefix="tag" TagName="addUser" Src="userform.ascx" %>
    
    .
    .
    .
    .
    </tr>
    <tag:addUser id="userInfo" Runat="server"></tag:addUser>
    <tr>
    .
    .
    .
    In userform.ascx.cs I added the following line:
    Code:
    protected userForm userInfo;
    I also had to write get and set for each textbox in the ascx file, but now it works fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width