Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
guyz,
how to create usercontrol for TextBox in asp.net. and set its properties
and use it in another Web Form.

Regards,
aamir
Posted

A user control is a kind of composite control that works much like an ASP.NET Web page —you can add existing Web server controls and markup to a user control, and define properties and methods for the control. You can then embed them in ASP.NET Web pages, where they act as a unit.

User controls are substantially easier to create, because you can reuse existing controls. They make it particularly easy to create controls with complex user interface elements.

Refer:
ASP.NET User Controls Overview[^]

If you have developed an ASP.NET Web page and would like to access its functionality throughout your application, you can make some minor alterations to the page to change it to a user control.
Refer: How to: Convert Web Forms Pages into ASP.NET User Controls[^]

How to: Create ASP.NET User Controls[^]
How to: Include ASP.NET User Controls in Web Pages[^]
 
Share this answer
 
Hi,
User controls are great for encapsulating markup, controls, and code that you need repeatedly throughout your site. To some extent, they look a bit like server controls in that they can contain programming logic and presentation that you can reuse in your pages. However, rather than dragging existing ones from the VWD Toolbox, you need to create your own user controls and then add them to your ASPX pages.
Your UseControl can be one of two things:
1. A granular bit of UI that renders information passed from a Controller
2. A granular bit of UI that renders information from an application-wide data source

Follow the links below for more information:
User controls in ASP .NET[^]
ASP.NET User Controls[^]
Events in UserControls[^]
 
Share this answer
 
prasad,
i have gone thru the above articles but i m stuck somewhere.
the values in web form where i m calling the Usercontrol textbox its not working?.
example:
when i set the value of Maxlenth='10' its not working on Web form
<uc1:textboxusercontrol id="TextBoxUsercontrol1" runat="server" xmlns:uc1="#unknown">
FieldName="lblPatientName" Tablename="table1" moduleName="PatientHistory" onkeypress="return CharCounter(this.id)"
VariableName="@p1" MaxLength="10"/>


but when i give the same MaxLength='10' on .ascx form
<asp:textbox id="txtLogIn" runat="server" height="22px" width="193px" xmlns:asp="#unknown">
it work fine.

what could be the issue
 
Share this answer
 
Comments
Prasad_Kulkarni 25-Jul-12 6:40am    
Stop posting your questions or comments as answer.

For your issue:
You can directly use binding to achieve what you want:
usercontrol
textbox maxlength="{Binding MaxTextLength}"/
/usercontrol

I din't used '<','>' for 'userControl' & 'textbox' as it not appears in comment if i use it.
You need to assign the edmx object to the DataContext property of UserControl, and the edmx object should contains a property which name should be something like "MaxTextLength".
aamir07 25-Jul-12 7:27am    
the post u have given is not relevant to my requirement.

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