Accessing custom control properties

E

Eric

Hello, I've created a custom control and want to set
properties in the aspx page.

<%@ Page language="c#" Codebehind="test_control2.aspx.cs"
AutoEventWireup="false"
Inherits="oldtownclovis_dotnet.test_control2" %>
<%@ Register TagPrefix="aspCustomerGrid"
TagName="CustomerGrid" Src="test_user_control.ascx"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN" >

<html>
<head>
<title>test_control2</title>
<LINK rel="stylesheet" type="text/css"
href="http://localhost/oldtownclovis_dotnet/include/otc_nor
mal.css">
</head>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">
<aspCustomerGrid:CustomerGrid
id="CustomerGrid" runat="server">
<!-- can i set the properties
here? -->
</aspCustomerGrid:CustomerGrid>
</form>

</body>
</html>


How do I set the public properties of the control from
within the customer control's tag?

Thanks,

Eric
 
V

Victor Garcia Aprea [MVP]

Hi Eric,

Define a public property in your user control class and then add an
attribute to the usercontrol tag named after your property, ie:
[C#]
public String YourProperty {
get{ ... }
set{ ... }
}
..ASPX
<prefix:YourUSerControlType runat="server" YourProperty="blah" />

You won't be able to set this property using the Properties window at
design-time, you will need to directly edit the markup, thats a limitation
in the current bits.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top