|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Enthusiast
![]() Join Date: Jan 2005
Location: Toronto
Posts: 70
|
User control and Page
Hi, I am buiding a small signup application using .net with c#. I have a Page (index.aspx) and I am loading seperate user contorls inside Page form dynamically on click. Now I have created a button on the Page and how do I retrieve all the values when I click that button? The user control contains all the form fields. Please help me on this or suggest how I can do this in very efficent way.
Thank you. |
|
|
|
|
|
#2 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Oct 2004
Location: kolkata
Posts: 808
|
It should drag on that page....but when clicking on the button it visibility true.
|
|
|
|
|
|
#3 |
|
SitePoint Member
Join Date: Mar 2006
Posts: 7
|
User Control File:
<script language="C#" runat="server"> void SubmitBtn_Click ( object src, EventArgs e ) { myLabel.Text += "Your user id is " + User.Text + "<br>"; myLabel.Text += "Your password is " + Pass.Text + "<br>"; } </script> <script language="C#" runat="server"> public String UserId { get { return User.Text; } set { User.Text = value; } } public String Password { get { return Pass.Text; } set { Pass.Text = value; } } </script> <table> <tr> <td><b>Login: </b></td> <td><ASP:TextBox id="User" runat="server"/></td></tr> <tr> <td><b>Password: </b></td> <td><ASP:TextBox id="Pass" TextMode="Password" runat="server"/></td></tr> <tr> <td></td> <td><ASP:Button Text="Click Here" OnClick="SubmitBtn_Click" runat="server"/></td></tr> <tr> <td ColSpan=2><ASP:Label id="myLabel" runat="server"/></td></tr> </table> ----------------------------------------- Forms.aspx <%@ Register tagPrefix="myCtrls" tagName="Login" src=".\controls\login.ascx" %> <html> <body> <form runat="server"> <myCtrls:Login id="myLogin" runat="server"/> </form> </body> </html> Is it help 2 u? cheers Sathya Last edited by sathiya_rr; Mar 23, 2006 at 12:19. |
|
|
|
|
|
#4 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Oct 2004
Location: Portugal, Lisboa
Posts: 841
|
myLogin.UserId ?
myLogin.Password ? |
|
|
|
|
|
#5 |
|
SitePoint Enthusiast
![]() Join Date: Jan 2005
Location: Toronto
Posts: 70
|
I am really sorry. This doesnt' lead me anywhere. I really wanted to create an instance for the created user control and start accessing its methods and variables also web controls. After added the user control into ma aspx page i have created an instance in code behind file of the aspx.
Control aControl myLogin; and when I try to get its methods and variables I am not able to do it. I am really curious if we can create an instance for the user controls and access it methods and variables. Thank you. |
|
|
|
|
|
#6 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Oct 2004
Location: Portugal, Lisboa
Posts: 841
|
To be hable to access the UserControls Controls in the Page you have to expose them in the UserControl, because they are declared as protected. Only public members are visible outside the class.
You don't need to create an instante of the UserControl in your Page class, you already have one, the one you added in the Page "html". You have exposed the Text property of two TextBoxes (User and Pass). To access them in the Page you use the "dot notation". myLogin.UserId myLogin.Password Another note when you declared "Control aControl myLogin" (with no need) you declared it as Control and not as your UserControl Type. Therefore you can't access the properties of the UserControl Type. Just declaring it isn't enough, you would have to instantiate it, other wise it would be null. Last edited by pufa; Mar 24, 2006 at 11:05. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 20:17.









Linear Mode
