Go Back   SitePoint Forums > Forum Index > Program Your Site > .NET
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Mar 20, 2006, 09:07   #1
MessedUpSoul
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.
MessedUpSoul is offline   Reply With Quote
Old Mar 20, 2006, 23:22   #2
ujjwal
SitePoint Guru
 
ujjwal's Avatar
 
Join Date: Oct 2004
Location: kolkata
Posts: 808
It should drag on that page....but when clicking on the button it visibility true.
ujjwal is offline   Reply With Quote
Old Mar 23, 2006, 11:43   #3
sathiya_rr
SitePoint Member
 
sathiya_rr's Avatar
 
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.
sathiya_rr is offline   Reply With Quote
Old Mar 23, 2006, 17:57   #4
pufa
SitePoint Guru
 
pufa's Avatar
 
Join Date: Oct 2004
Location: Portugal, Lisboa
Posts: 841
myLogin.UserId ?

myLogin.Password ?
pufa is offline   Reply With Quote
Old Mar 24, 2006, 08:18   #5
MessedUpSoul
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.
MessedUpSoul is offline   Reply With Quote
Old Mar 24, 2006, 10:14   #6
pufa
SitePoint Guru
 
pufa's Avatar
 
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.
pufa is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 20:17.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved