471,071 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Help with web user control

I'm building a small web application - I started out placing all my code in
one file (config.aspx). As I continue to add code though it was becoming
very unwieldy.

After doing some searching online I found an article which suggested I might
place some of the code into web user controls. I created two new files
(general_info.ascx and store_front.ascx) and placed two chunks of code in
each.

I then registered the controls at the top of config.aspx:
<%@ Register TagPrefix="UU" TagName="general_info" Src="~/general_info.ascx"
%>
<%@ Register TagPrefix="UU" TagName="store_front" Src="~/store_front.ascx"
%>

And I also add the controls to config.aspx:
<UU:general_info id="general_info1" runat="server" />
<UU:store_front id="store_front1" runat="server" />

However I'm getting the following errors:
Element 'general_info' is not a known element. This can occur if there is a
compilation error in the Web site.

Element 'store_front' is not a known element. This can occur if there is a
compilation error in the Web site.

I can't seem to figure out where I went wrong. I'm a bit new at
csharp/asp.net so I'm sure I'm just doing something stupid wrong. Could
anyone point me in the right direction?

Thank You,
Brad Baker
Mar 11 '07 #1
11 2029
On Mar 11, 5:17 pm, "Brad Baker" <b...@nospam.nospamwrote:
I'm building a small web application - I started out placing all my code in
one file (config.aspx). As I continue to add code though it was becoming
very unwieldy.

After doing some searching online I found an article which suggested I might
place some of the code into web user controls. I created two new files
(general_info.ascx and store_front.ascx) and placed two chunks of code in
each.

I then registered the controls at the top of config.aspx:
<%@ Register TagPrefix="UU" TagName="general_info" Src="~/general_info.ascx"
%>
<%@ Register TagPrefix="UU" TagName="store_front" Src="~/store_front.ascx"
%>

And I also add the controls to config.aspx:
<UU:general_info id="general_info1" runat="server" />
<UU:store_front id="store_front1" runat="server" />

However I'm getting the following errors:
Element 'general_info' is not a known element. This can occur if there is a
compilation error in the Web site.

Element 'store_front' is not a known element. This can occur if there is a
compilation error in the Web site.

I can't seem to figure out where I went wrong. I'm a bit new at
csharp/asp.net so I'm sure I'm just doing something stupid wrong. Could
anyone point me in the right direction?

Thank You,
Brad Baker
Was the compilation successful?

The code you've posted here looks correct.

Mar 11 '07 #2
Was the compilation successful? <

No - it produces the error mentioned in my original post (Element 'XXX' is
not a known element....)

I found a post which suggested that I needed to group my user controls into
a folder - that seemed to resolve the original problem only to create new
errors. :-)

Now my problem seems to be references in my user controls to code still in
the config.aspx file. I'm a bit befuddled as to where to go from here. I'm
still searching the net and reading a few reference books but if anyone has
any ideas I would appreciate any suggestions. (Below are a couple of the
errors from detailed error output)

Thanks Again,
Brad

-----

webcontrols\general_info.ascx(48) : error BC30456:
'general_info_view_linkbutton_click' is not a member of
'ASP.webcontrols_general_info_ascx'.
AddHandler __ctrl.Click, AddressOf
Me.general_info_view_linkbutton_click
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

webcontrols\store_front.ascx(170) : error BC30456:
'store_front_edit_linkbutton_click' is not a member of
'ASP.webcontrols_store_front_ascx'.
AddHandler __ctrl.Click, AddressOf
Me.store_front_edit_linkbutton_click
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

webcontrols\store_front.ascx(179) : error BC30451: Name 'convert_to_html' is
not declared.
dataBindingExpressionBuilderTarget.Text =
System.Convert.ToString(
convert_to_html(Convert.ToString(Eval("additional_ domains"))) ,
System.Globalization.CultureInfo.CurrentCulture)

-----

"Alexey Smirnov" <al************@gmail.comwrote in message
news:11*********************@8g2000cwh.googlegroup s.com...
On Mar 11, 5:17 pm, "Brad Baker" <b...@nospam.nospamwrote:
>I'm building a small web application - I started out placing all my code
in
one file (config.aspx). As I continue to add code though it was becoming
very unwieldy.

After doing some searching online I found an article which suggested I
might
place some of the code into web user controls. I created two new files
(general_info.ascx and store_front.ascx) and placed two chunks of code in
each.

I then registered the controls at the top of config.aspx:
<%@ Register TagPrefix="UU" TagName="general_info"
Src="~/general_info.ascx"
%>
<%@ Register TagPrefix="UU" TagName="store_front"
Src="~/store_front.ascx"
%>

And I also add the controls to config.aspx:
<UU:general_info id="general_info1" runat="server" />
<UU:store_front id="store_front1" runat="server" />

However I'm getting the following errors:
Element 'general_info' is not a known element. This can occur if there is
a
compilation error in the Web site.

Element 'store_front' is not a known element. This can occur if there is
a
compilation error in the Web site.

I can't seem to figure out where I went wrong. I'm a bit new at
csharp/asp.net so I'm sure I'm just doing something stupid wrong. Could
anyone point me in the right direction?

Thank You,
Brad Baker

Was the compilation successful?

The code you've posted here looks correct.

Mar 11 '07 #3

"Brad Baker" <br**@nospam.nospamwrote in message
news:ew**************@TK2MSFTNGP04.phx.gbl...
>Was the compilation successful? <
On Mar 11, 10:56 pm, "Brad Baker" <b...@nospam.nospamwrote:
Was the compilation successful? <

No - it produces the error mentioned in my original post (Element 'XXX' is
not a known element....)
Well that was at run-time I guess, but ok, now I see what is the problem.

webcontrols\general_info.ascx(48) : error BC30456:
'general_info_view_linkbutton_click' is not a member of
'ASP.webcontrols_general_info_ascx'.
AddHandler __ctrl.Click, AddressOf
Me.general_info_view_linkbutton_click
It means you don't have a method called general_info_view_linkbutton_click
in general_info.ascx.vb

Either remove the line with AddHandler...., or create a method you refered.

>
webcontrols\store_front.ascx(170) : error BC30456:
'store_front_edit_linkbutton_click' is not a member of
'ASP.webcontrols_store_front_ascx'.
AddHandler __ctrl.Click, AddressOf
Me.store_front_edit_linkbutton_click
The same problem.

webcontrols\store_front.ascx(179) : error BC30451: Name 'convert_to_html'
is
not declared.
dataBindingExpressionBuilderTarget.Text =
System.Convert.ToString(
convert_to_html(Convert.ToString(Eval("additional_ domains"))) ,
System.Globalization.CultureInfo.CurrentCulture)
The same problem, a function with name convert_to_html cannot be found
Mar 11 '07 #4
Hi Brad,

Welcome to ASP.NET programming world!

For your specific issue, I think Alexey's suggestion should work. Please
feel free to let us know if you still have trouble to run your code.

Usually I would recommend new ASP.NET developer to following resources when
getting started with ASP.NET:

* Microsoft ASP.NET QuickStarts Tutorial
(http://www.dotnetjunkies.com/quickst...uickstart.aspx)

Although it's for ASP.NET 1.1, but it's from startup and should get you
familiar with ASP.NET. For example, you specific question is about Web User
Control and this is the specific tutorial for it:
http://www.dotnetjunkies.com/quickst...bpagelets.aspx

* ASP.NET 2.0 QuickStart Tutorial
(http://quickstarts.asp.net/QuickStar...t/Default.aspx)

This covers some new features available in ASP.NET 2.0.

* INFO: ASP.NET Roadmap (http://support.microsoft.com/kb/305140)

Although it's written for ASP.NET 1.1, but it contains many useful KBs to
various topics in ASP.NET world.
Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 12 '07 #5
Hi Brad,

Have you solved the issue? Please feel free to let us know if there's
anything unclear. Thanks.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 15 '07 #6
No - I'm still confused.:) As mentioned previously I had all my code in one
file (config.aspx) - this includes functions, and two formview controls
which contain several other controls.

Anyway I pulled the two formview controls out and made each a user control
(general_info.ascx and storefront_info.ascx). Now of course my application
no longer works.

So the part I am confused about is weather I should:

- Pull my functions out of config.aspx and place them inside of my ascx
files - the same code in both files between <scriptand </scripttags

- Pull my functions out of config.aspx and place them inside of ascx.cs
files?

And do I need to do anything with my functions? I.E. do they need to be
re-formated as properties and sub routines?

Alternatively I wonder if user controls are really what I want - maybe I
should be looking at web parts instead?

I'm sorry - I'm sure these must seem like silly questions. If you have any
suggestions I would appreciate the assistance.

Thanks
Brad

BTW - In the link you included below
(http://www.dotnetjunkies.com/quickst...bpagelets.aspx) all
of the samples are broken links.
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:LI**************@TK2MSFTNGHUB02.phx.gbl...
Hi Brad,

Have you solved the issue? Please feel free to let us know if there's
anything unclear. Thanks.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 16 '07 #7
Hi Brad,

There're no silly questions, :)

Getting started with ASP.NET can be daunting at first, especially when your
mind is used to the stateful world of client/server applications. That's
why I suggested to start with the tutorial and the roadmap to learn it step
by step, :)

Anyway, let's get back to the issue in this post: based on my
understanding, you was using a WebForm and you later decided to move some
controls into its own Web User Control and use this Web User Control on the
WebForm.

If your FormView will be used by your WebForm, by moving it into a User
Control, it will no longer be referenced directly by your WebForm.
Therefore your code must need have some changes accordingly.

Yes some of your functions, such as the event handlers of the FormView will
be needed to move along with the FormView into the User Control's code
behind class.

I think it's not easy to answer your question easily since the full code
listing is not included here. Anyway, I suggest you first to understand the
Web User Control: the tutorial and documentation should help you. By the
way, I just checked the tutorial URL, it's working on my side, what error
or exception are you seeing when clicking on the samples links?

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 16 '07 #8
On this page:
http://www.dotnetjunkies.com/quickst...bpagelets.aspx
All of the "view source" links are broken for me.

Here are two examples of the functions I am talking about:

===========
/*
* Switch the formview mode to view
*/
protected void store_front_view_linkbutton_click(object sender, EventArgs e)
{
store_front_formview.ChangeMode(FormViewMode.ReadO nly);
}

/*
* Takes data stored in the database and formats it for output on the page.
* For instance new lines, commas, and spaces are converted to line breaks,
*/
protected string htmlize(string additional_domains) {

string strContent = additional_domains;

// Try to strip out extraneous characters and add in html line breaks
strContent = strContent.Replace("\n", "<br/>");
strContent = strContent.Replace(", ", "<br/>");
strContent = strContent.Replace(",", "<br/>");
strContent = strContent.Replace(" ", "<br/>");

// Regular Expresson to find URLs and "html-ize" them
Regex urlregex = new Regex(@"(([\w.]+\/?)\S*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
strContent = urlregex.Replace(strContent,"<a href=\"http://$1\"
target=\"_blank\">$1</a>");
return strContent;
}
===========
These functions are referenced in my user controls (as part of a formview):
===========
<td class="right_labels"Mode:</td>
<td>
<asp:LinkButton ID="ViewLinkButton" runat="server"
OnClick="store_front_view_linkbutton_click">View</asp:LinkButton>
</td>

.... more code ....

<td class="right_labels">URLS:</td>
<td><asp:Label ID="additional_domains" runat="server" Text='<%#
htmlize(Convert.ToString(Eval("additional_domains" ))) %>'></asp:Label</td>
===========

So would I move this function to the codebehind for my user control? If so
don't I have to rewrite my function? I'm hesitant to do that as I have
around 10 functions - some of which are quite complex. Also both of my new
user controls use a lot of the same functions - so there would be quite a
lot of code duplication.

My original goal was to compartmentalize my code into different peices so
that it was more managable. User controls seemed like the right solution but
if I have to re-write all my code I wonder if there isn't a better way of
acheiving the same result. Or if I am better off just leaving all the code
in one file. :-\

Best Regards
Brad Baker

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:RH**************@TK2MSFTNGHUB02.phx.gbl...
Hi Brad,

There're no silly questions, :)

Getting started with ASP.NET can be daunting at first, especially when
your
mind is used to the stateful world of client/server applications. That's
why I suggested to start with the tutorial and the roadmap to learn it
step
by step, :)

Anyway, let's get back to the issue in this post: based on my
understanding, you was using a WebForm and you later decided to move some
controls into its own Web User Control and use this Web User Control on
the
WebForm.

If your FormView will be used by your WebForm, by moving it into a User
Control, it will no longer be referenced directly by your WebForm.
Therefore your code must need have some changes accordingly.

Yes some of your functions, such as the event handlers of the FormView
will
be needed to move along with the FormView into the User Control's code
behind class.

I think it's not easy to answer your question easily since the full code
listing is not included here. Anyway, I suggest you first to understand
the
Web User Control: the tutorial and documentation should help you. By the
way, I just checked the tutorial URL, it's working on my side, what error
or exception are you seeing when clicking on the samples links?

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 16 '07 #9
Alright - you'll love this.

The source of all my headaches was this: <script runat="server">
Instead of this: <script language="C#" runat="server">

What was I thinking? :-) Everything is now working as expected. Thanks for
all your help and patience. I truelly appreciate it.

Warm Regards,
Brad Baker

By the way - This site:
http://quickstarts.asp.net/QuickStar...l/default.aspx
was very useful: I missed it the first time I went through the links.
"Brad Baker" <br**@nospam.nospamwrote in message
news:O4*************@TK2MSFTNGP06.phx.gbl...
On this page:
http://www.dotnetjunkies.com/quickst...bpagelets.aspx
All of the "view source" links are broken for me.

Here are two examples of the functions I am talking about:

===========
/*
* Switch the formview mode to view
*/
protected void store_front_view_linkbutton_click(object sender, EventArgs
e) {
store_front_formview.ChangeMode(FormViewMode.ReadO nly);
}

/*
* Takes data stored in the database and formats it for output on the page.
* For instance new lines, commas, and spaces are converted to line breaks,
*/
protected string htmlize(string additional_domains) {

string strContent = additional_domains;

// Try to strip out extraneous characters and add in html line breaks
strContent = strContent.Replace("\n", "<br/>");
strContent = strContent.Replace(", ", "<br/>");
strContent = strContent.Replace(",", "<br/>");
strContent = strContent.Replace(" ", "<br/>");

// Regular Expresson to find URLs and "html-ize" them
Regex urlregex = new Regex(@"(([\w.]+\/?)\S*)",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
strContent = urlregex.Replace(strContent,"<a href=\"http://$1\"
target=\"_blank\">$1</a>");
return strContent;
}
===========
These functions are referenced in my user controls (as part of a
formview):
===========
<td class="right_labels"Mode:</td>
<td>
<asp:LinkButton ID="ViewLinkButton" runat="server"
OnClick="store_front_view_linkbutton_click">View</asp:LinkButton>
</td>

... more code ....

<td class="right_labels">URLS:</td>
<td><asp:Label ID="additional_domains" runat="server" Text='<%#
htmlize(Convert.ToString(Eval("additional_domains" ))) %>'></asp:Label>
</td>
===========

So would I move this function to the codebehind for my user control? If so
don't I have to rewrite my function? I'm hesitant to do that as I have
around 10 functions - some of which are quite complex. Also both of my new
user controls use a lot of the same functions - so there would be quite a
lot of code duplication.

My original goal was to compartmentalize my code into different peices so
that it was more managable. User controls seemed like the right solution
but if I have to re-write all my code I wonder if there isn't a better way
of acheiving the same result. Or if I am better off just leaving all the
code in one file. :-\

Best Regards
Brad Baker

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:RH**************@TK2MSFTNGHUB02.phx.gbl...
>Hi Brad,

There're no silly questions, :)

Getting started with ASP.NET can be daunting at first, especially when
your
mind is used to the stateful world of client/server applications. That's
why I suggested to start with the tutorial and the roadmap to learn it
step
by step, :)

Anyway, let's get back to the issue in this post: based on my
understanding, you was using a WebForm and you later decided to move some
controls into its own Web User Control and use this Web User Control on
the
WebForm.

If your FormView will be used by your WebForm, by moving it into a User
Control, it will no longer be referenced directly by your WebForm.
Therefore your code must need have some changes accordingly.

Yes some of your functions, such as the event handlers of the FormView
will
be needed to move along with the FormView into the User Control's code
behind class.

I think it's not easy to answer your question easily since the full code
listing is not included here. Anyway, I suggest you first to understand
the
Web User Control: the tutorial and documentation should help you. By the
way, I just checked the tutorial URL, it's working on my side, what error
or exception are you seeing when clicking on the samples links?

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

================================================= =
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================= =

This posting is provided "AS IS" with no warranties, and confers no
rights.


Mar 17 '07 #10
"Brad Baker" <br**@nospam.nospamwrote in message
news:un**************@TK2MSFTNGP03.phx.gbl...
What was I thinking? :-)
That's what you get for coding inline... ;-)

<ducks>
Mar 17 '07 #11
Hi Brad,

Thank you very much for the follow-up. I'm glad the issue is finally
solved.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 20 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by bie2 | last post: by
13 posts views Thread by Lloyd Sheen | last post: by
5 posts views Thread by Dan Nash | last post: by
3 posts views Thread by Tim::.. | last post: by
3 posts views Thread by Joe | last post: by
reply views Thread by leo001 | last post: by

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.