Building Web User Controls in ASP.NET
Web user controls are the same as ASP.NET controls. But the difference is that ASP.NET controls are those are already defined by Microsoft and we can create web user controls.
We can create our own controls in ASP.NET. If you want to develop a control which has two textboxes and one button like login control in ASP.NET 2005, you can develop in ASP.NET.
Even you can bind one or more HTML controls also into one User control with your own functionality and properties.
Creating Web user Control:
Open Microsoft visual studio --> File -->New website
After creating the website folder, Right click on solution explorer
-->Add New Item ---> Web User Control --> Add
Then drag and drop one text box, one label and one Button control.
And also add some functionality for those controls.(Client side script or server side script)
Here I use the javascript as client side script.
The code for web user control look like below.
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" >
<title>Untitled Page</title>
<script type="text/javascript">
function display()
{
var txt_value=document.getElementById('mycontrol1_txt1').value;
if(txt_value=='')
{
window.alert('Please enter your name');
document.getElementById('mycontrol1_txt1').focus();
return false;
}
document.getElementById('mycontrol1_lbl1').innerHTML = txt_value;
return false;
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div>
<asp:Label ID="lbl1" runat="Server" ></asp:Label> <br />
<asp:TextBox ID="txt1" runat="Server" ></asp:TextBox> <br />
<asp:Button Text="Click" ID="btn" OnClientClick="return display();"
runat="Server" />
</div>
</form>
</body>
</html>
Next >>
Subscribe
Filter by APML