How to use Ascx User Control [Resolved]

Posted by Akiii under Regular Expressions on 4/26/2011 | Points: 10 | Views : 65862 | Status : [Member] | Replies : 20
How can we use ascx user control in a page ??
Can anybody explain it with an example !

Thanks and Regards
Akiii




Responses

Posted by: Tijut2k on: 4/26/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved

Example User Control for creating Tab

Add New Web User Control to Your Project
then Add some link button and set the properties and events

eg:

ascx code

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Menu.ascx.cs"
Inherits="ProjectName.UserControl.ComplaintCaptureMenu" %>

<div class="uc-menulinks-container">
<asp:LinkButton ID="lnkHome" runat="server" CssClass="uc-menulinks" OnClick="lnkHome_Click"
CausesValidation="False">Home</asp:LinkButton>
<asp:LinkButton ID="lbnServices" runat="server" Visible="true" CssClass="uc-menulinks" OnClick="lbnServices_Click"
CausesValidation="False" Text="Services Detail" ></asp:LinkButton>

<asp:LinkButton ID="lbnLog" runat="server" Visible="true" CssClass="uc-menulinks" OnClick="lbnLog_Click"
CausesValidation="False" Text="Log Details" ></asp:LinkButton>

</div>


ascx.cs

protected void lnkComplaint_Click(object sender, EventArgs e)
{
Response.Redirect("~/Home.aspx");
}
like that......


In Content page

First register the user control

eg:

<%@ Register Src="~/UserControl/Menu.ascx" TagName="mpMenu" TagPrefix="uc2" %>

then the control using innerpage

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<uc2:mpMenu runat="server" ID="mpMenu1" />

</asp:Content>

Best Regard's
Tiju Thankachan

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 5/24/2011 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
Hi,

Refer this link,

http://msdn.microsoft.com/en-us/library/aa479318.aspx

Regards,
Susan

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/25/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Hi akiii,
In .net we are using the .net controls like <asp:Button>,<asp:TextBox> etc.
Here tagPrefix is asp and tagName is Button,TextBox etc.

Like that we can create user controls using ascx page.
After creating the user controls , for using those controls in our page first we have to register it in our page
Eg:-<%@ Register Src="~/UserControl/Menu.ascx" TagName="mpMenu" TagPrefix="uc2" %>
now we can use this control whereever we like in that page by writing
<uc2:mpMenu runat="server" ID="mpMenu1" />
(here I mention the example given by Tijut2K. Menu.ascx is the user control page)

Thanks,


Nitha Deepak

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/25/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Akiii,
Refer the link......
http://msdn.microsoft.com/en-us/library/6hws6h2t(v=VS.90).aspx
Thanks,

Nitha Deepak

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 4/26/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Check below links

http://www.codeproject.com/KB/user-controls/myusercontrol.aspx
http://asp.net-tutorials.com/user-controls/using/

Thanks
Karthik
www.f5Debug.net

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mesh_2010 on: 4/27/2011 [Member] Starter | Points: 25

Up
0
Down

Hi Akii,

First you can create usercontrol (.ascx) page your project. If you want design your usercontrol page.

then you call page to .asp page above head section.
Exm.
[code]
<%@ Register Src="~/folder_name/LeftBot.ascx" TagName="LeftBot" TagPrefix="uc2" %>
[/code]

Thanks
RameSH sinGH

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 4/27/2011 [Member] Bronze | Points: 25

Up
0
Down
@karthik.....

Thank you for the links....
is usercontrol just like a plug-in that can be used in various pages by inheriting it??

Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 4/27/2011 [Member] Bronze | Points: 25

Up
0
Down
@Tijut2k

Thanks for posting the code......but the concept of usercontrol is not very clear in my mind......
can you give me more examples??

Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 4/27/2011 [Member] Bronze | Points: 25

Up
0
Down
@Mesh_2010......

thanks for the response......

TagName is the name of the ascx file or the usercontrol that i have created......?

but what is tag-prefix??

Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mesh_2010 on: 4/28/2011 [Member] Starter | Points: 25

Up
0
Down

Hi Akii,

Tag-prefix defined bottom of page (required your project where u want)

[code]
<%@ Register Src="~/folder_name/LeftBot.ascx" TagName="LeftBot" TagPrefix="uc2" %>

<uc2:LeftBot ID="leftbot" runat="server" />
[/code]

Thanks
RameSH sinGH

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 4/28/2011 [Member] Bronze | Points: 25

Up
0
Down
@Mesh_2010......

thanks for your response....

Thanks
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/25/2011 [Member] Bronze | Points: 25

Up
0
Down
HI SUSAN........

Thanks for the link......

I was following one link, but it is giving me error when i try to compile the project....
I am pasting the link here, see if you can make a user-control by following the steps...

http://asp.net-tutorials.com/user-controls/introduction/

Thanks and Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/25/2011 [Member] Bronze | Points: 25

Up
0
Down
hi nitha.....

Thanks for the reply......
I understand your answer......i think user-control is just like master-pages......we can include it wherever and whenever we want in our pages....
Suppose i have a calender which is included in 7 to 8 pages then i can build a user-control and use it as per the requirement in those pages.....

But can you tell me one-thing, can usercontrol be used in desktop applications too or there are is an another way around ??

Thanks and Regards
Akiii



Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/25/2011 [Member] Bronze | Points: 25

Up
0
Down
hi nitha....

thanks for the link......much appreciated...

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/25/2011 [Member] Bronze | Points: 25

Up
0
Down
Akiii... if you got the correct solution pls mark it as resolved.

Nitha Deepak

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/8/2012 [Member] Bronze | Points: 25

Up
0
Down
In one page we can use more than one UserControls..
Please refer this link too..
http://www.beansoftware.com/ASP.NET-Tutorials/User-Control.aspx

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/8/2012 [Member] Bronze | Points: 25

Up
0
Down
In one page we can use more than one UserControls..
User controls are one of ASP.NET methods to increase reusability of code, implement encapsulation and reduce maintenance. User control is similar to web page
Please refer this link too..
http://www.beansoftware.com/ASP.NET-Tutorials/User-Control.aspx

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 6/8/2012 [Member] Bronze | Points: 25

Up
0
Down
@Muhsinathk....thats a very good link indeed !


Thanks and Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 6/8/2012 [Member] Bronze | Points: 25

Up
0
Down
Thank youu..

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nisar.Net on: 6/29/2013 [Member] Starter | Points: 25

Up
0
Down
thanks really helped

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response