473,666 Members | 2,116 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 1394
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.c om";
%>
...
<A href="<%=href%> ">http://www.microsoft.com </A>
<asp:HyperLin k id="HyperLink1 " NavigateUrl = "<%=href%>" style="Z-INDEX:
101; LEFT: 8px; POSITION: absolute; TOP: 112px"
runat="server"> http://www.microsoft.c om</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.QuerySt ring 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.c om";
%>
...
<A href="<%=href%> ">http://www.microsoft.com </A>
<asp:HyperLi nk id="HyperLink1 " NavigateUrl = "<%=href%>" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 112px"
runat="server" >http://www.microsoft.c om</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 misunderstandin g 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.P age
{
protected Footer Footer1;
protected System.Web.UI.W ebControls.Hype rLink HyperLink1;
public string href = "abcd";
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Footer1.testStr ing = 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 misunderstandin g 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.P age
{
protected Footer Footer1;
protected System.Web.UI.W ebControls.Hype rLink HyperLink1; public string href = "abcd";
private void Page_Load(objec t sender, System.EventArg s e) {
// Put user code to initialize the page here Footer1.testStr ing = 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
1253
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 the compiler tries to compile the pages that use the UserControls before compiling the UserControls, and therefore does not know that the property exists when compiling. The only way around this that I have found is to use the CType() function as...
5
1160
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 the compiler tries to compile the pages that use the UserControls before compiling the UserControls, and therefore does not know that the property exists when compiling. The only way around this that I have found is to use the CType() function as...
4
1066
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 the compiler tries to compile the pages that use the UserControls before compiling the UserControls, and therefore does not know that the property exists when compiling. The only way around this that I have found is to use the CType() function as...
7
2133
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 CType(Me.FindControl("admin" & CStr(section("buttontext")).Replace(" ", "")), adminsection2).RefreshSection() Next End Sub
0
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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 we have to send another system
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.