Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Set value of UserControl property

Reply
Thread Tools

Set value of UserControl property

 
 
Jim Ross [MVP]
Guest
Posts: n/a
 
      09-24-2003
I have a User Control with a property defined (in the ASCX, not in
CodeBehine. The property is defined like this:

<script runat=server language=vb>
Private m_deptName As String
<Bindable(True)>Public Property DepartmentName As String
Get
Return m_deptName
End Get
Set
m_deptName = value
End Set
End Property
</script>

When I put the control on a page and set the propery like this, it
works:
<uc1:Header id="headerCtl" runat=server DepartmentName="Some
Department"></uc1:Header>

However, if I use a variable that has been defined on the page and
then set the user control property to the value, it does not work, the
value is never set. There are no errors thrown, but, as I said, the
value is not set.

<script runat=server language=vb>
Dim pageDeptName As String = "Page Department Name"
</script>
....
<uc1:Header DepartmentName="<%= pageDeptName %>"
runat=server></uc1:Header>



Jim Ross
MS MVP [ASP.NET][VC/MFC emeritus]

To send email, change 'lotsofspamthroughhere' to 'msn' but please ask all questions in the newsgroups, not via private mail
 
Reply With Quote
 
 
 
 
Jacob Yang [MSFT]
Guest
Posts: n/a
 
      09-24-2003
Hi Jim,

Please right click the page and select "View Source". Based on my research
and experience, we can find the following in the HTML code:

<%= pageDeptName %>

The value of DepartmentName is set to "<%= pageDeptName %>". That should be
the reason for this issue.

Does it answer your question? If I have misunderstood your concern, please
feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
<MCSD>
Get Secure! ĘC www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
 
Jim Ross [MVP]
Guest
Posts: n/a
 
      09-24-2003
Jacob,

Another bit of information. If I do a "View Source" on the rendered
page in the browser, I see <%= ValueForProperty %> (that is, whatever
the expressoin was in the control's declaratives) where the actual
value should be. Since the browser treates the < .... > as an HTML
tag, the effect is that nothing displays.

If I remove the ".." from around the <%= %> block, the page throws an
error that <% %> is not allowed within page tags.

http://www.velocityreviews.com/forums/(E-Mail Removed) (Jacob Yang [MSFT]) wrote:

>Hi Jim,
>
>Please right click the page and select "View Source". Based on my research
>and experience, we can find the following in the HTML code:
>
><%= pageDeptName %>
>
>The value of DepartmentName is set to "<%= pageDeptName %>". That should be
>the reason for this issue.
>
>Does it answer your question? If I have misunderstood your concern, please
>feel free to let me know.
>
>Best regards,
>
>Jacob Yang
>Microsoft Online Partner Support
><MCSD>
>Get Secure! ĘC www.microsoft.com/security
>This posting is provided "as is" with no warranties and confers no rights.


Jim Ross
MS MVP [ASP.NET][VC/MFC emeritus]

To send email, change 'lotsofspamthroughhere' to 'msn' but please ask all questions in the newsgroups, not via private mail
 
Reply With Quote
 
Jacob Yang [MSFT]
Guest
Posts: n/a
 
      09-25-2003
Hi Jim,

You are right in this issue.

Based on my research and experience, an explanation for this issue is "a
server tag cannot contain <% ... %> constructs".

For example, we can try to assign the value from a variable to the "href"
attribute of a hyperlink as the following:

<%
string href;
href = "http://www.microsoft.com";
%>

<A href=" <%=href%>"> http://www.microsoft.com </A>

The above HTML code works fine. But we cannot do the similar thing for the
NavigateUrl property of the asp:hyperlink.

I hope it helps.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ĘC www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
<value> could not be set on property <property name> TonyDyer General Computer Support 0 02-14-2012 03:25 PM
Getting a property of a control inside a usercontrol, from another usercontrol Fabiano ASP .Net 2 06-03-2005 09:56 AM
how to pass dynamic value to property in usercontrol moid ASP .Net 2 01-23-2004 03:55 PM
Accessing UserControl property value from page control Iain ASP .Net 3 11-18-2003 12:46 AM
'property value' could not be set on property 'propertyname' KJ ASP .Net Web Controls 0 08-26-2003 06:08 PM



Advertisments