Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
This button is user control
ASP.NET
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="user.ascx.cs" Inherits="Linque_Practice.user1" %>
Basheer
<p>
    &nbsp;</p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Add" 
    Width="64px" />

    <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Delete" 
    Width="64px" />


In aspx page i have three textbox

XML
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <br />
second<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <br />
    add
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>


i want want when i click the add button its in usercontrole it should add the number from first 2 text and result store in 3rd text box

How to invoke the button click event from usercontrole to in code behind (.cs file)
Posted
v2

The framework has a way of wiring this through some convention.

You normally declare a public delegate and define a public event in your user control using that delegate. In the control markup use OnEventName="PageMethod". Where EventName is the name of the event defined in the usercontrol and PageMethod is the method in the aspx page. Trigger the event from user control code-behind.

Say delegate is as follows:
public delegate void ClickHandler();


Event definition inside user control class is as follows:
public event ClickHandler Clicked;


Write code which fires the event. In this case button click:
public void btnSubmit_Click(object s, EventArgs e)
{
if(Clicked != null) Clicked();
}


Finally the markup:
ASP.NET
<cc1:uc1 id="uc1"  runat="server"  önClicked="UcClicked"></cc1:uc1>


Make sure there exists a page a method on the page; it should not be private.
 
Share this answer
 
v2
Code could be as simple as Click(o, null) where o is the object and null the event argument which we may not need in case of firing the event via code behind.
 
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