Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a user control and want to write the code in aspx file.
The scenario contains a View Post page (Default.aspx) and an Add Post page (AddPost.aspx). The View Post page allows you to select a post from a drop-down list and then displays the post's title and content along with who created the post and when it was posted. The Add Page allows you to author a new post and preview it before submitting it.

AddPost.aspx:-
<asp:Panel ID="PreviewPostPanel" runat="server" Visible="False">
                <!--
                    Todo:
                    The PreviewPostPanel of the AddPost.aspx page contains a
                     PostUserControl called PreviewPostUserControl.
                -->



            </asp:Panel>

Here i want to add a user control.

Default.aspx
XML
<asp:Panel ID="ViewPostPanel" runat="server">
                <!--
                    Todo:
                    The original contents of the ViewPostPanel on the Default.aspx page are in the new PostUserControl.ascx file, and the ViewPostPanel now contains an instance of the PostUserControl called ViewPostUserControl.
                -->



                <h3>
                    <asp:Label ID="TitleLabel" runat="server" />
                </h3>
                <asp:Label ID="ContentLabel" runat="server" />
                <br />
                <asp:Label ID="PostInformationLabel" runat="server" />
            </asp:Panel>

The TODO part we have to do
Posted
Updated 25-Apr-11 23:57pm
v3
Comments
Ankur\m/ 26-Apr-11 7:21am    
So start doing, what are you waiting for? We are happy to help if you show us that you have tried hard and have specific issues.
Monjurul Habib 27-Apr-11 15:22pm    
please clarify your question. where you need help?

1 solution

Do you mean to register the Control so you can call it anywhere in your code???

By placing this line of code at the top of my page

<%@ Register Src="~/Controls/MyControl.ascx"TagName="myControl" TagPrefix="pp" %>


I can call the Control with
<pp:mycontrol id=""myControl1"" runat=""server"" xmlns:pp="#unknown" />




so for example you could have your default page like

XML
<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="Default.aspx.cs" Inherits="WEB.MyWebsite.UI._Default"
Title="My Website" MasterPageFile="~/Template.master" %>


<%@ Register Src="~/Controls/MyControl.ascx" TagName="myControl" TagPrefix="pp" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="Server">

       <pp:myControl ID="myControl1" runat="server" />

</asp:Content>



Is that what you meant?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900