Tuesday 15 May 2012

c# - How to communicate between user controls in Asp.Net -



c# - How to communicate between user controls in Asp.Net -

i have 5 files.

default.aspx search.ascx searchsql.ascx grid.ascx gridsql.ascx

i have registered ascx files in default.aspx page , utilize properties expose controls default page. , works great.

my issue how send info , 4th between different ascx pages? if register on of give me circular file reference error.

using public properties, have search.ascx registered on gridsql.ascx pass search parameters gridsql string, , gridsql.ascx on grid.ascx file pass sql string grid databind.

there has got much easier way pass info & 4th between pages, or wrong? when seek register on other page pass info page sent it, circular file reference error. have heard few resolutions changing file structure, have tried, , batch, kills performance. believe have spent days trying find resolutions on this. going comment on questions stack not allow me until have 50 rep.

my company requiring utilize separate files on , cant believe best way communicate between user controls.

proper way want bubble kid control's event parent.

then allow parent forwards event other controls.

note: here demo. might want rename delegates , methods create sense scenario.

search (user command fires event) <%@ command language="c#" autoeventwireup="true" codebehind="search.ascx.cs" inherits="demowebform.search" %> <asp:textbox runat="server" id="searchtextbox" /> <asp:button runat="server" id="searchbutton" text="search" onclick="searchbutton_click" /> public delegate void messagehandler(string searchtext); public partial class search : system.web.ui.usercontrol { public event messagehandler searchtext; protected void searchbutton_click(object sender, eventargs e) { searchtext(searchtextbox.text); } } gridsql (user control)

finally, gridsql.ascx receives search text.

<%@ command language="c#" autoeventwireup="true" codebehind="gridsql.ascx.cs" inherits="demowebform.gridsql" %> <asp:label runat="server" id="searchtextlabel"/> public partial class gridsql : system.web.ui.usercontrol { public void searchtextmethod(string searchtext) { searchtextlabel.text = searchtext; } } parent <%@ page language="c#" autoeventwireup="true" codebehind="parent.aspx.cs" inherits="demowebform.parent" %> <%@ register src="~/search.ascx" tagname="search" tagprefix="uc1" %> <%@ register src="~/gridsql.ascx" tagname="gridsql" tagprefix="uc2" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <uc1:search id="search1" runat="server" /> <uc2:gridsql id="gridsql1" runat="server" /> </form> </body> </html> public partial class parent : system.web.ui.page { protected void page_load(object sender, eventargs e) { search1.searchtext += m => gridsql1.searchtextmethod(m); } }

c# asp.net user-controls

No comments:

Post a Comment