Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,449 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,146 people online right now. Registration is fast and FREE... Join Now!




Changing form to user Control

 
Reply to this topicStart new topic

Changing form to user Control

Footsie
5 Aug, 2008 - 02:58 AM
Post #1

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 305



Thanked: 4 times
Dream Kudos: 50
My Contributions
I created a web form called JarControl.aspx and then tried to convert it to become a user control, JarControl.ascx
Attached Image

As you can see in my pic, I have changed all the extensions to ascx
And I have changed the code behind file to inherit from System.Web.UI.UserControl.
Code:
CODE

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JarControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}


It still gives me that annoying red underline (see pic) and Validation errors such as:
Validation (ASP.Net): Attribute 'Control' is not a valid attribute of element 'Page'.

I've tried saving and building the project a few times - doesn't get rid of it.


User is offlineProfile CardPM
+Quote Post

Bardy
RE: Changing Form To User Control
6 Aug, 2008 - 12:00 AM
Post #2

New D.I.C Head
*

Joined: 30 Jul, 2008
Posts: 11

Why not just create a new UserControl, then dump everything in JarControl into the usercontrol. Copy all the stuff in the body of the aspx page to asxc, and everything under PageEvent in aspx.cs to the ascx.cs.

Thats should sort out your problem.
User is offlineProfile CardPM
+Quote Post

Footsie
RE: Changing Form To User Control
6 Aug, 2008 - 11:17 PM
Post #3

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 305



Thanked: 4 times
Dream Kudos: 50
My Contributions
Thanks Bardy.

I realise that that would probably fix the problem, but I was following an exercise in a book that indicated that there should be no problem doing the conversion. Thing is, the control works perfectly, I used it in another web form. It's just the Visual Studio validation that seems to be glitchy.

EDIT:
After closing everything down and re-opening Visual Studio and the project the errors seem to have disappeared.

This post has been edited by Footsie: 7 Aug, 2008 - 12:26 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 02:50PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month