473,508 Members | 2,233 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UserControls & Properties

Hi

I have created a range of usercontrols for displaying
various bits of information. My question is if I wish to
pass a parameter to the UserControl from the host page,
is this possible?

I have tried setting an attribute in the Server Tag which
only works if I use a constant as it won't allow the <%
=xxxx%> parameters within the control!

Any ideas?

Thanks in advance

Andy
Nov 17 '05 #1
4 1386
Hi Andy,

Based on my research, a server tag cannot contain <% ... %> constructs. To
assign a value to an attribute of a server tag, we should use server-side
code via the id of that server tag from within code-behind class or or
inline <script runat=server> </script> section.

I have tested this issue with the hyperlink control and gotten the same
result. The following is the testing code:
...
<%
string href;
href = "http://www.microsoft.com";
%>
...
<A href="<%=href%>">http://www.microsoft.com </A>
<asp:HyperLink id="HyperLink1" NavigateUrl = "<%=href%>" style="Z-INDEX:
101; LEFT: 8px; POSITION: absolute; TOP: 112px"
runat="server">http://www.microsoft.com</asp:HyperLink>
...

The "<%=href%>" works as expected in the HTML Hyperlink but it does not
work in 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.

Nov 17 '05 #2
Hi Jacob

I don't think I explained things clearly enough :-) I am
aware of the Server Controls property assingments using
server side code.

My problem is with User Controls with a .ascx extension
you don't seem to be able to access these from the code
behind file and cannot allocate properties using the <%%>
inline code syntax either.

You can access the Request.QueryString object in the code
behind file for the control and it does pick up in page
parameters passed within the host file, but this does not
solve my problem.

Any further thoughts?

Regards

Andy
-----Original Message-----
Hi Andy,

Based on my research, a server tag cannot contain <% ... %> constructs. To assign a value to an attribute of a server tag, we should use server-side code via the id of that server tag from within code- behind class or or inline <script runat=server> </script> section.

I have tested this issue with the hyperlink control and gotten the same result. The following is the testing code:
...
<%
string href;
href = "http://www.microsoft.com";
%>
...
<A href="<%=href%>">http://www.microsoft.com </A>
<asp:HyperLink id="HyperLink1" NavigateUrl = "<%=href%>" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 112px"
runat="server">http://www.microsoft.com</asp:HyperLink>
...

The "<%=href%>" works as expected in the HTML Hyperlink but it does not work in 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.
.

Nov 17 '05 #3
Hi Andy,

I am sorry if there is any misunderstanding but we are able to access the
property of the User Control (ascx) from the code behind file. Pleaes refer
to the following code snippet.

...
public class WebForm1 : System.Web.UI.Page
{
protected Footer Footer1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
public string href = "abcd";
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Footer1.testString = href;
}
...

Footer1 is a User Control.

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
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4
Hi again

Ha Ha!

It doesn't add the reference in to the client ascx file
automatically, once I manually add these protected
references in to my controls it works :-)

Excellent news that makes a whole lot more sense now doh!

Thank you again Jacob, efficient as ever superb support.

best regards

Andy
-----Original Message-----
Hi Andy,

I am sorry if there is any misunderstanding but we are able to access the property of the User Control (ascx) from the code behind file. Pleaes refer to the following code snippet.

...
public class WebForm1 : System.Web.UI.Page
{
protected Footer Footer1;
protected System.Web.UI.WebControls.HyperLink HyperLink1; public string href = "abcd";
private void Page_Load(object sender, System.EventArgs e) {
// Put user code to initialize the page here Footer1.testString = href;
}
...

Footer1 is a User Control.

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
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1240
by: Nathan Sokalski | last post by:
In several of my UserControls I add properties. If I access these properties in the CodeBehind of the pages that use the controls, I recieve an error when compiling. The reason for this is because...
5
1154
by: Nathan Sokalski | last post by:
In several of my UserControls I add properties. If I access these properties in the CodeBehind of the pages that use the controls, I recieve an error when compiling. The reason for this is because...
4
1056
by: Nathan Sokalski | last post by:
In several of my UserControls I add properties. If I access these properties in the CodeBehind of the pages that use the controls, I recieve an error when compiling. The reason for this is because...
7
2119
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.