472,354 Members | 1,956 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

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 1340
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
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
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
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
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.