|
-
Apr 13th, 2004, 04:00 AM
#1
Thread Starter
Frenzied Member
Value from usercontrol
I have this code:
[code]
Protected Sub Komponenter1_ClickUserControl(ByVal sender As Object, ByVal e As System.EventArgs) Handles Komponenter1.ClickUserControl
Dim userC As UserControl = CType(sender, UserControl)
If Not userC Is Nothing Then
Dim userC2 As UserControl = CType(sender, UserControl)
Dim txt1 As String
Dim i As Integer
txt1 = userC.ID
If txt1.Length = 12 Then
i = 1
Else
i = 2
End If
txt1 = CInt(txt1.Substring(11, i))
userC2.ID = "Komponenter" + CStr(txt1)
userC2.Visible = True
end sub
[code]
which works fine. But if I change the code in the two last line to
Code:
userC2.ID = "Komponenter" + CStr(txt1+1)
userC2.Visible = True
then I receive an error:
Code:
Multiple controls with the same ID 'Komponenter2' were found. FindControl requires that controls have unique IDs.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Multiple controls with the same ID 'Komponenter2' were found. FindControl requires that controls have unique IDs.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Multiple controls with the same ID 'Komponenter2' were found. FindControl requires that controls have unique IDs.]
System.Web.UI.Control.FillNamedControlsTable(Control namingContainer, ControlCollection controls) +134
System.Web.UI.Control.FillNamedControlsTable(Control namingContainer, ControlCollection controls) +203
System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +164
System.Web.UI.Control.FindControl(String id) +9
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +74
System.Web.UI.Page.ProcessRequestMain() +1277
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Why can't I do that?
The code that I write is needed for an app with a lot of order lines where the next order line becomes visible if the current order line is clicked.
-
Apr 16th, 2004, 10:22 PM
#2
I wonder how many charact
Wow...
Well, you declare txt1 as a string, then assign a numeric value to it using CINT(somestring).
When you changed the second to last line, now you're saying CSTR(txt1+1), which is really funky, because txt1 is a string value.
Logically, how do you add the numeric value 1 to a string that represents a number "100". It certainly is not txt1 + 1, I don't care if it worked by accident for you, which is what it did, perhaps because the VB compiler is so forgiving, but as you found out, the underlying .Net framework is not.
Let's first get this code under control:
VB Code:
Dim userC As UserControl = CType(sender, UserControl)
If Not userC Is Nothing Then
Dim userC2 As UserControl = CType(sender, UserControl)
Dim txt1 As String
Dim i As Integer = 1
[b]Dim newID As Integer[/b]
txt1 = userC.ID
If Not txt1.Length = 12 Then i =2
[b]newID = Integer.Parse(txt1.Substring(11, i))
newID += 1
'for the change that you wanted, txt1 + 1 that caused your error
userC2.ID = String.Concat("Komponenter", newID.ToString)[/b]
userC2.Visible = True
Last edited by nemaroller; Apr 16th, 2004 at 10:41 PM.
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
|