User Controls and ASPX.CS

J

JV

I have created a user control UCQuery.acx. It consists of
a number of drop down list boxes. I created this control
because the same drop down list boxes must appear on
several aspx pages for user selection of data for input
into a database query.

So I have the ascx and I add it to my wp.aspx:

<%@ Register TagPrefix="uc1" TagName="UCQuery"
Src="UCQuery.ascx" %>

and

<uc1:ucquery id="UCQuery1" runat="server"></uc1:ucquery>

Now in my wp.aspx.cs I want to reference UCQuery1 but I
get an error.

I need to call public methods in the ascx from my aspx.cs
in order to get the user selections from the control and
pass them on.

Am I out of line in thinking this can be done with a user
control?

Thanks in advance,

JV
 
C

Cowboy \(Gregory A. Beamer\)

JV said:
I have created a user control UCQuery.acx. It consists of
a number of drop down list boxes. I created this control
because the same drop down list boxes must appear on
several aspx pages for user selection of data for input
into a database query.

Good reason for a user control. I have seen an app where the designer had a
control for everything, even those that would never be repeated.
So I have the ascx and I add it to my wp.aspx:

<%@ Register TagPrefix="uc1" TagName="UCQuery"
Src="UCQuery.ascx" %>

and

<uc1:ucquery id="UCQuery1" runat="server"></uc1:ucquery>

Now in my wp.aspx.cs I want to reference UCQuery1 but I
get an error.

Add the following line to your CodeBehind:

protected UCQuery UCQuery1;

template = protected {Class Name} {Name of object in page};

Then you should be able to do:

UCQuery1.property1 = "";

Not sure why Microsoft does not have this happen automagically when a
control is dropped, as I routinely work with controls in CodeBehind.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
B

Billy Billerson

What the deuce is this:

template = protected {Class Name} {Name of object in
page};
 

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

Top