|
-
Sep 11th, 2003, 05:23 AM
#1
Thread Starter
Frenzied Member
UserControl and setting text
I have a simple user control:
Code:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="Length.ascx.vb" Inherits="GF.Length" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:TextBox ID=txtLength Width=30px CssClass=tastFelt Runat=server></asp:TextBox>
I've added 10 instaces of this in my application. How do I set the text-property for each of these user controls? Let's say the content should be 5,10,15... in the text boxes.
-
Sep 11th, 2003, 08:23 AM
#2
PowerPoster
You need to go to your code behind and add protected members for each usercontrol with the exact same name as the control on your form.
-
Sep 11th, 2003, 08:58 AM
#3
Thread Starter
Frenzied Member
Great, thanks.
The next problem I have is how I can read the value from this user control. The user control name is Dimension and the first textbox is named txtLength1. How can I read this value, when I submit?
I have tried this:
Code:
sub test_calc()
dim test as single
test = CSng(dimension1_txtLength1.text)
end sub
but it doesn't work. Whats wrong?
-
Sep 11th, 2003, 11:39 AM
#4
PowerPoster
The usercontrol will need to expose properties. For example:
Code:
public string TextBoxContents {
get {
return txtName.Text;
}
set {
txtName.Text = value;
}
}
Remember, a usercontrol is like a black box, it's internal data is hidden from the outside (concept of encapsulation). Only expose what needs to be exposed.
-
Sep 12th, 2003, 12:38 AM
#5
Thread Starter
Frenzied Member
Great, just what i needed. Thanks a lot.
-
Sep 12th, 2003, 01:18 AM
#6
Thread Starter
Frenzied Member
Sorry for disturbing again, but I can't make it work. Let' say my simple user control is:
Code:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="WebUserControl1.ascx.vb" Inherits="GF.WebUserControl1" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:TextBox ID=txtLength1 Runat=server>0</asp:TextBox>
How would the code be for storing the content of the textbox to a new variable?
-
Sep 12th, 2003, 01:05 PM
#7
PowerPoster
You would need to add this to your code-behind:
Code:
public string Length {
get {
return txtLength1.Text;
}
set {
txtLength1.Text = value;
}
}
-
Sep 13th, 2003, 02:10 AM
#8
Thread Starter
Frenzied Member
I am using VB.Net, I guess the code you wrote is C#. I also think there is another way: To declare the class where the user control is placed, like this, also added to the code behind:
Code:
protected testUserControl as ClassName.testUserControl.testUc.
But I can't find out how get and set the property, do you know the code in VB that I need to insert in the codebehind?
-
Sep 17th, 2003, 01:03 AM
#9
Thread Starter
Frenzied Member
Now I've found out that I don't need to specify the classname, but what should the code be for VB instead of C#? Do you know where I can find some tutorials concerning User Controls?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|