how to call a method of one user control in another user control
-
iam having two user controls u1 and u2 .i have one public method in u1 .now i want to call this method in u2.how can i handle this one .
-
iam having two user controls u1 and u2 .i have one public method in u1 .now i want to call this method in u2.how can i handle this one .
Remember i order to do that in U2 you must register the U1 and after that you can access your u1 method in U2 like this
u1.Mymethod();
Hope this Helps
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
Remember i order to do that in U2 you must register the U1 and after that you can access your u1 method in U2 like this
u1.Mymethod();
Hope this Helps
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
this is not working ...is any other way to do that one
-
this is not working ...is any other way to do that one
What is it that is not working ? Tell me what you did because that is how its done.
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
What is it that is not working ? Tell me what you did because that is how its done.
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
hi Maseko, actually in my application there are neary 25 webpages which are using two user controls tat are banner and navgation user control..but in each page the ids of these two controls are different and they have used according to the pagenames..now there is a situation that the method of one user control u1 is required to used in the u2 when a button in the u2 is clicked..
-
hi Maseko, actually in my application there are neary 25 webpages which are using two user controls tat are banner and navgation user control..but in each page the ids of these two controls are different and they have used according to the pagenames..now there is a situation that the method of one user control u1 is required to used in the u2 when a button in the u2 is clicked..
Good Morning lakshmichawala I will show you an Example of how you do it. i will create a Small Example. First i will create a usercontrol and name i U1 like and it will have a method that will display a string like this cs will look like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class U1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{} public String Message() { return "Message from U1 User control"; }
}
and the html will be like this
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="U1.ascx.cs" Inherits="U1" %>
<asp:Label ID="lblU1" runat="server" Text="Usercontrol 1"></asp:Label>and second thing is to create a Second user control and name it U2
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="U2.ascx.cs" Inherits="U2" %>
<%@ Register src="U1.ascx" tagname="U1" tagprefix="uc1" %>
<asp:Label ID="lblU2" runat="server" Text="User Control 2"></asp:Label><p>
</p>
<p>
</p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />as you can see i have registered the U1 and in my U2 i can use the Function that i have made public like this in the button click
protected void Button1_Click(object sender, EventArgs e)
{
U1 obj = new U1();String Message; Message = obj.Message(); Response.Write(Message); }
and a hardcoded message will come from the U1. Hope this helps Thanks
Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/
-
hi Maseko, actually in my application there are neary 25 webpages which are using two user controls tat are banner and navgation user control..but in each page the ids of these two controls are different and they have used according to the pagenames..now there is a situation that the method of one user control u1 is required to used in the u2 when a button in the u2 is clicked..
If you're trying to interact between two already loaded instances of different user controls I would possibly use an event. For example, when u2 button is clicked raise an event to the calling page, the calling page can then call the method in u2 as it already knows about it. Alternatively, you can create a property on u2 of type u1 and the consuming page could set the property on u2 to the instance of u1 on the page, u2 will then have access to u1 and its methods.