Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have 3 controls (1 label, 1 textbox , 1 button)in my web user control page....
i have 3 forms on which button(of web user control) will perform different operations(insert, update ,delete)

how can i achieve this????

web user control page

XML
<script runat="server">
public string LabelText
{
set
{
myLabel.Text = value;
}
}
public string Text
{
get
{
return myTextBox.Text;
}
}
public string btntext
{
    set
    {
        Button1.Text = value;
    }
}
</script>
<p>
<asp:Label ID="myLabel" runat="server" Text="" Width="100" />
<asp:TextBox ID="myTextBox" runat="server" Text="" Width="200"
MaxLength="20" />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</p>




default1 page
XML
<%@ Register src="SmartBox.ascx" tagname="SmartBox" tagprefix="sp" %>
    <uc1:SmartBox ID="SmartBox1"  runat="server" btntext="Insert"  LabelText="ENTER:"/>


in default2 page 
<%@ Register src="SmartBox.ascx" tagname="SmartBox" tagprefix="sp" %>
    <uc1:SmartBox ID="SmartBox1" runat="server" btntext="delete"  LabelText="ENTER:"/>


how to operate opeartions of delete and insert on two forms with user control
Posted
Comments
vinodkumarnie 25-Jan-13 5:45am    
If you know the properties of get{} and set{}, you can achieve this easily in back-end code..

If you didn't get i will gave you the solution..

1 solution

XML
steps for creating web user control:

1.Add User Control in project Select "Web User Control" from New Item Window and name it .
2.Add following code to file .ascx

<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="ucImageViewer.ascx.cs" Inherits="ucImageViewer" %>

<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<asp:Image ID="Image1" runat="server" />// using image you can use label or text as per requirement
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="Button1" runat="server" Text="Original View"
OnClick="Button1_Click" />
</td>
</tr>
</table>
3. add event handler and perform required operation in ascx.cs file like:

protected void Button1_Click(object sender, EventArgs e)
{

}
4.Ad peroperites if any
5.Now to display Web User Control on Web Form in asp.net:
<%@ Register Src="ucControlName.ascx" TagName="somename" TagPrefix="uc" %>
here
Src - It specifies source of web user control.
TagPrefix - It Specifies Prefix for user control, i.e. Namespace to which it belong.
TagName - It Specifies Alias to the user control. i.e. Id to Control.
 
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