PDA

View Full Version : Help with UserControl



sharif
Feb 12, 2010, 11:07 AM
How can I notify the page from usecontrol. If I have textbox and a button on usercontrol when the button clicked I want the page to grab the textbox value and do something with it

Or if I have a grid in control I want to return the row was selected.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="compwizard.Test.test" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
<%@Register Src="~/Test/testc.ascx" TagName="testControl" TagPrefix="uc" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">

<ext:ResourceManager ID="ResourceManager1" runat="server" />
<uc:testControl ID="ucTest" runat="server" />


</form>
</body>
</html>


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="testc.ascx.cs" Inherits="compwizard.Test.testc" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
// this.Button1.Text = string.Concat("UserControl (", this.Name, ")");
}
}

[DirectMethod]
public void GetName()
{
/// X.Msg.Alert("Name", Search.Text).Show();
/// tell the main page to do something
}

</script>
<ext:TextField ID="Search" runat="server" FieldLabel="search"/>
<ext:Button ID="Button1" runat="server" Text="Search">
<Listeners>
<Click Handler="#{DirectMethods}.GetName();" />
</Listeners>
</ext:Button>

Vladimir
Feb 12, 2010, 11:30 AM
Hi,

There are few ways. For example, using delegates and events. If you type in the Google "ASP.NET page user control delegate communication" then you will see many articles regarding this topic


http://www.codeproject.com/KB/user-controls/Page_UserControl.aspx
http://www.codeproject.com/KB/user-controls/aspnetusercontrol3.aspx
http://aspalliance.com/1461_Page_and_User_Control_Communication.all
http://forums.asp.net/t/1279281.aspx

sharif
Feb 12, 2010, 11:34 AM
I thought Coolite uses different ways
thanks

Vladimir
Feb 12, 2010, 11:39 AM
I don't think that this topic specific for Coolite. It is "Page - User Control" or "MasterPage - ContentPage" communication problem. Therefore we have no any own way. By the way, what kind of the way did you expect? Any thoughts how to implement it is better than described on those articles?