usercontrol event
-
Ok! I know what you need! create a class (named ResponseEventArgs) that inherits the EventArgs and add a property named myValue. Like this
public class ResponseEventArgs : EventArgs
{
private String _myValue;
public String MyValue
{
get { return _myValue; }
set { _myValue = value; }
}
}Then in your ascx user control, add the event and the correct delegate
public delegate void ResponseEventHandler(object sender, ResponseEventArgs d);
public event ResponseEventHandler ResultOfMyText;
here you've added the event ResultOfMyText and the handler ResponseEventHandler. Now in the ascx user control add the event as a virtual function
[Description("Event that fires after button click of user control")]
protected virtual void OnResult_Show(ResponseEventArgs re)
{
if (ResultOfMyText != null)
ResultOfMyText(this, re);}
Now in button Click event of the user control, add the correct value to MyValue Property
//here is button_Click event of the user control
ResponseEventArgs re = new ResponseEventArgs();
re.MyValue = Txt_Value.Text;//You need a textbox named Txt_Value
OnResult_Show(re);then when you've added this user control, you'll see that it has a event named ResultOfMyText. Trigger that event, and you'll see that you have a d.MyValue in ResultEventArgs and will execute that event every time that you click on the button inside the user control. I hope this won't be confused ;)
-
so just the first part is in aspx right ?? public class ResponseEventArgs : EventArgs{ private String _myValue; public String MyValue { get { return _myValue; } set { _myValue = value; } }}
suchita
have you create a class with name ResponseEventArgs.cs?? the content of that class should have
private String _myValue;
public String MyValue
{
get
{ return _myValue; }
set { _myValue = value; }
}}if you've created! then look where it is! for example, if I've created the class in a folder named "Classes", I have to reference it like Classes.ResponseEventArgs ;) Ahh and the first part is from the ResponseEventArgs.cs class! the other parts are from the ascx userControl. And in the aspx page you will see the event ResultOfMyText and when you've triggered, it would look like this
protected void ResultOfMyText(object sender, ResponseEventArgs d)
{
String response = d.MyValue;
}modified on Wednesday, May 19, 2010 4:28 PM
-
have you create a class with name ResponseEventArgs.cs?? the content of that class should have
private String _myValue;
public String MyValue
{
get
{ return _myValue; }
set { _myValue = value; }
}}if you've created! then look where it is! for example, if I've created the class in a folder named "Classes", I have to reference it like Classes.ResponseEventArgs ;) Ahh and the first part is from the ResponseEventArgs.cs class! the other parts are from the ascx userControl. And in the aspx page you will see the event ResultOfMyText and when you've triggered, it would look like this
protected void ResultOfMyText(object sender, ResponseEventArgs d)
{
String response = d.MyValue;
}modified on Wednesday, May 19, 2010 4:28 PM
hey i still couldn't get out of it. Let me put down what all i did. I have one button and a textbox in usercontrol1.ascx page. the code inside this page is shown as: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Globalization; using System.Text; namespace ProjectRequestTest { public delegate void ResponseEventHandler(object sender, ResponseEventArgs d); public partial class usercontrol1 : System.Web.UI.UserControl { public event ResponseEventHandler ResultOfMyText; protected void Page_Load(object sender, EventArgs e) { } [Description("Event that fires after button click of user control")] protected virtual void OnResult_Show(ResponseEventArgs re) { if (ResultOfMyText != null) ResultOfMyText(this, re); } protected void Button1_Click(object sender, EventArgs e) { ResponseEventArgs re = new ResponseEventArgs(); re.MyValue = TextBox1.Text;//You need a textbox named Txt_ValueOnResult_Show(re); OnResult_Show(re); } } } now the ResponseEventArgs.cs class has code like this: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ProjectRequestTest { public class ResponseEventArgs : EventArgs { private String _myValue; public String MyValue { get { return _myValue; } set { _myValue = value; } } } } now for usercontrol.aspx page, i have one textbox and that usercontrol from ascx page. the code behind in this page is : using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ProjectRequestTest { public partial class usercontrol : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void ResultOfMyText(object sender, ResponseEventArgs d) { TextBox1.Text = d.MyValue; } } } but when i click the button, the textbox of aspx page is still not showing the value ?? What could have gone wrong ???
suchi
-
hey i still couldn't get out of it. Let me put down what all i did. I have one button and a textbox in usercontrol1.ascx page. the code inside this page is shown as: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Globalization; using System.Text; namespace ProjectRequestTest { public delegate void ResponseEventHandler(object sender, ResponseEventArgs d); public partial class usercontrol1 : System.Web.UI.UserControl { public event ResponseEventHandler ResultOfMyText; protected void Page_Load(object sender, EventArgs e) { } [Description("Event that fires after button click of user control")] protected virtual void OnResult_Show(ResponseEventArgs re) { if (ResultOfMyText != null) ResultOfMyText(this, re); } protected void Button1_Click(object sender, EventArgs e) { ResponseEventArgs re = new ResponseEventArgs(); re.MyValue = TextBox1.Text;//You need a textbox named Txt_ValueOnResult_Show(re); OnResult_Show(re); } } } now the ResponseEventArgs.cs class has code like this: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ProjectRequestTest { public class ResponseEventArgs : EventArgs { private String _myValue; public String MyValue { get { return _myValue; } set { _myValue = value; } } } } now for usercontrol.aspx page, i have one textbox and that usercontrol from ascx page. the code behind in this page is : using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ProjectRequestTest { public partial class usercontrol : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void ResultOfMyText(object sender, ResponseEventArgs d) { TextBox1.Text = d.MyValue; } } } but when i click the button, the textbox of aspx page is still not showing the value ?? What could have gone wrong ???
suchi
Maybe it is showing! all the code is correct! :confused: i'm sure that if you put a breakpoint, the d.MyValue is the textbox.Text of user control. I've copied the text you have written! and it works for me! that simple! Have you added the event in the aspx page??
<%--'This is how i have named my user control (TestUserControl)'--%>
< uc1:TestUserControl ID="UsrCtr_Test" runat="server"
OnResultOfMyText="ResultOfUserControlTextBox" / >to codebehind
//triggered by the event 'OnResultOfMyText="ResultOfUserControlTextBox"'
protected void ResultOfUserControlTextBox(object sender, ResponseEventArgs d)
{
Txt_MyTextBox.Text = d.MyValue;
}good luck! I hope you finish with this ;P ;P
-
Maybe it is showing! all the code is correct! :confused: i'm sure that if you put a breakpoint, the d.MyValue is the textbox.Text of user control. I've copied the text you have written! and it works for me! that simple! Have you added the event in the aspx page??
<%--'This is how i have named my user control (TestUserControl)'--%>
< uc1:TestUserControl ID="UsrCtr_Test" runat="server"
OnResultOfMyText="ResultOfUserControlTextBox" / >to codebehind
//triggered by the event 'OnResultOfMyText="ResultOfUserControlTextBox"'
protected void ResultOfUserControlTextBox(object sender, ResponseEventArgs d)
{
Txt_MyTextBox.Text = d.MyValue;
}good luck! I hope you finish with this ;P ;P
-
Ok no problem! that's why we are here! ;)