Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NETC#4.0.NET4
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
 
<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
<%@ 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 22-Jan-13 0:42am
Comments
vinodkumarnie at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 Dnyaneshwar@Pune 1,300
1 Sergey Alexandrovich Kryukov 660
2 ravikhoda 300
3 OriginalGriff 299
4 Manas Bhardwaj 240
0 Sergey Alexandrovich Kryukov 11,194
1 OriginalGriff 6,867
2 Peter Leow 4,795
3 Abhinav S 3,838
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid