C# - Assign Delegate Event Handler From Dynamically Added Child Control

Apr 14, 2010

I have a control that handles commenting. In this control, I have set a delegate event handler for sending an email.

I then have various types of controls, e.g. blog, articles etc, each of which may or may not have the commenting control added (which is done dynamically with me not knowing the id's), i.e. the commenting control is added outside this control. Each of these controls handles it's emailing differently(hence the event).

What I'm trying to determine, is how to assign the event in the parent control. At the moment, I'm having to recursively search through all the controls on the page until I find the comment control, and set it that way. Example below explains:

COMMENTING CONTROL

public delegate void Commenting_OnSendEmail();
public partial class Commenting : UserControl
{
public Commenting_OnSendEmail OnComment_SendEmail();
private void Page_Load(object sender, EventArgs e)
{
if(OnComment_SendEmail != null)
{
OnComment_SendEmail();
}
}
}

PARENT CONTROL

public partial class Blog : UserControl
{
private void Page_Load(object sender, EventArgs e)
{
Commenting comControl = (Commenting)this.FindControl<Commenting>(this);
if(comControl != null)
{
comCtrol.OnComment_SendEmail += new Commenting_OnSendMail(Blog_Comment_OnSendEmail);
}
}
}

EDIT:

The reason I ask is that if I search from this.Page as the initial control, I am worried about time taken to search down the control tree to find it. Each different type of page would be different in how many control it would have. On some testing, it returns back quite quickly the result.

View 1 Replies


Similar Messages:

Web Forms :: Event Not Firing On Dynamically Added Control

Feb 23, 2011

While I am using a "Telerik" control here it shouldn't be any different I guess;

[code]....

What happens is that the control is created and rendered;

When I change value in the Combo box a Post-Back happens.

HOWEVER, the event RadComboBoxSelectedIndexChanged does not fire. Also when I am back at the page the new value is not saved; Obviously, i recreate the control every time. If I don't I get a ViewState error. Seems to me that there some ViewState management problem, but I cannot identify it...

View 2 Replies

C# - Accessing A Control Dynamically Added To A Placeholder During An Event

Mar 30, 2011

I'm creating an ASP.NET control dynamically based on a value selected in a dropdown; for instance the field can be a textbox or a checkbox (for now), and then it gets added to a placeholder control. However, I'm unsure how to retrieve the value - using the placeholder's FindControl method returns null although I'm specifying the ID when I create the control.

Here's my code:

[code]....

View 2 Replies

Event Handling For A Dynamically Added User Control?

Apr 26, 2010

I have a user control say SearchVendor.ascx which contains 4 buttons a gridview and another user control. I need to load the control dynamically actually as a modal pop up

I get this code

var uc = Page.LoadControl("~/blah/VendorProductSearch.ascx") as VPSearch;
uc.ShowVPSearch(true);
_tempPlaceHolder.Controls.Add(uc);

it works fine the control gets loaded properly but onclick of any button the second time the control disappears ?

I want the dynamically added control to remain until the user clicks on the cancel button

View 2 Replies

Web Forms ::dynamically Added Control In Any Page Event?

Jul 23, 2010

How can I get the placement of dynamically added control in any page event.

View 6 Replies

State Management :: How To Make An Image Control (dynamically Added To A GridView Column In It's RowDataBound Event)

Mar 28, 2010

I have a gridview that on it's RowDataBound event I dynamically add Image Controls to some columns.

The problem is that I lose these images on the next PostBack.

OBS: The GridView's EnableViewState propertie is already set to true

I know about the page lifecycle, but how can I persist these images if I have to add them on the RowDataBound event?

In addittion, if I add a static TemplateColumn with an Image Control and I set it's ImageUrl propertie inside the RowDataBound event it will obviously persist between postbacks. The problem is that I don't know how many columns with images I'll have, it's defined on the datasource.

[Code]....

View 8 Replies

C# - Getting Dynamically Added Child Controls To Display In The UI

Dec 20, 2010

I am trying to create a RadioButtonListWithOther class that extends the RadoButtonList but I can't get the "Other" textbox to render on the page. When I step through while debugging I can see the control in the parent control's Controls collectio but it still doesn't render.

public class RadioButtonListWithOther : RadioButtonList
{
private TextBox _otherReason;
public RadioButtonListWithOther()
{
_otherReason = new TextBox();
_otherReason.TextMode = TextBoxMode.MultiLine;
_otherReason.Rows = 6;
_otherReason.Width = Unit.Pixel(300);
_otherReason.Visible = true;
}
protected override void CreateChildControls()
{
this.Controls.Add(_otherReason);
this.EnsureChildControls();
base.CreateChildControls();
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
_otherReason.Enabled = false;
if (OtherSelected())
{
_otherReason.Enabled = true;
}
base.OnSelectedIndexChanged(e);
}
public override string Text
{
get
{
if (OtherSelected())
{
return _otherReason.Text;
}
return base.Text;
}
set
{
base.Text = value;
}
}
public override bool Visible
{
get
{
return base.Visible;
}
set
{
//Push visibility changes down to the children controls
foreach (Control control in this.Controls)
{
control.Visible = value;
}
base.Visible = value;
}
}
private bool OtherSelected()
{
if (this.SelectedItem.Text == "Other")
{
return true;
}
return false;
}
}

Here is my code to add an instance of this control to the WebForm:

protected override void CreateChildControls()
{
var whyMentorOptions = new Dictionary<string, string>();
whyMentorOptions.Add("Option 1", "1");
whyMentorOptions.Add("Option 2", "2");
whyMentorOptions.Add("Option 3", "3");
whyMentorOptions.Add("Other", "Other");
mentorWhy = new RadioButtonListWithOther
{
DataSource = whyMentorOptions
};
this.mentorWhy.DataTextField = "Key";
this.mentorWhy.DataValueField = "Value";
this.mentorWhy.DataBind();
Form.Controls.Add(mentorWhy);
base.CreateChildControls();
}

View 1 Replies

DropDownList Added In Runtime - Event Handler Not Getting Fired

Jan 19, 2011

Protected Sub ddl_selectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim a As String = ""
'this does not get fired
End Sub
<asp:GridView ID="GridViewAssignment" runat="server" BackColor="White" BorderColor="White"
BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None"
Width="100%">
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#86A4CA" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#808080" Font-Bold="True" ForeColor="#E7E7FF" />
</asp:GridView>
Protected Sub GridViewAssignment_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridViewAssignment.RowDataBound
Dim dateApplicationCreatedCell As TableCell = e.Row.Cells(0) 'app created on
Dim typeOfReview As TableCell = e.Row.Cells(7) 'type
Dim QCCell As TableCell = e.Row.Cells(8) 'qc
Dim dateReviewAssignedCell As TableCell = e.Row.Cells(9) 'date assigned
Dim reviewerNameCell As TableCell = e.Row.Cells(10) 'reviewer
Dim dateReviewCompletedCell As TableCell = e.Row.Cells(11) 'date completed review
Dim ddl As DropDownList
If e.Row.RowIndex <> -1 Then
If dateReviewAssignedCell.Text.Trim = " " Then
dateReviewAssignedCell.Text = Now.Date
End If
Dim sqlCondition As String = String.Empty
If dateReviewCompletedCell.Text.Trim = " " Then
Dim nameToSelect As String
If reviewerNameCell.Text.Trim <> " " Then
Dim dateReviewAssigned As Date = dateReviewAssignedCell.Text
Dim elapsedSinceAssigned As Long = DateDiff(DateInterval.Day, dateReviewAssigned.Date, Now.Date, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.Jan1)...............................

View 1 Replies

Button Event Handler Added Programmaticly With Class Method Does Not Fire?

Jun 22, 2010

I am building a web site with visual web developer 2010

I have a class (autoButton) that adds a button to a panel (on Default.aspx) and a handler w/i the same class (classifyEventHandler)

The button appears fine, but when clicked the even doesnt fire, what am I doing wrong?

I tried locating the event handler in default.aspx, but it was not found :P

Imports Microsoft.VisualBasic
Public Class autoButton
Public Sub makeClassifyButton(ByVal theCell As Object)
Dim myButton As New Button
myButton.Text = "classify"
myButton.ID = "b_classify_" + theCell.ID
AddHandler myButton.Click, AddressOf classifyEventHandler
theCell.Controls.Add(myButton)
End Sub
Private Sub classifyEventHandler(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("done?!")
End Sub
End Class

View 1 Replies

Data Controls :: Assign JQuery Click Event Handler To GridView Row

May 7, 2015

How we call a function on selecting a row in ASP.Net ....

View 1 Replies

C# - Web Control Added In .master Control Type Not Found In Child Page?

Jun 7, 2010

I have a Web Site project, and within it I have a user Web Control defined in an ascx file.The control is added to the Site.Master, and it shows up correctly on the page and everything is fine.I need to override some of the control's fields on one of the pages that derive from Site.Master.

// In OnLoad:
MyControlName control = (MyControlName) Page.Master.GetBaseMasterPage().FindControl("controlID"));

The issue is that MyControlName doesn't register as a valid Type on the child page. If I add a second instance of the control to the child page directly, the above works as needed, but if the control isn't placed directly on the page, and instead is only defined in the master page, the type is undefined. The control is not in a namespace, and is defined within the project, so I don't know why it is having such an issue location the appropriate type.If I put a breakpoint in the OnLoad, the type listed for the control is ASP.my_control_name_ascx, but using that does not work either. Why can't the child class reference the correct type? Can I fix this?

View 3 Replies

Web Forms :: Composite Control Loses Subscribed Event/delegate?

Jan 18, 2010

I have created a custom composite control basically with two checkboxes. I have created a subscribable event, and the consumer has subscribes to it. But when I go to excute it, the delegate reference is null. What am I missing and why is it losing its subscribed events?

[Code]....

I am using VS2008 SP1 targeting .Net 2/3.5SP1 web site.

View 2 Replies

Forms Data Controls :: Child Gridview Editing On Dynamically Added Nested Gridview

Jan 3, 2010

I have a nested gridview dynamically added. It seems I resolved all issues with the loading this control on a parent page along with other controls and I can trigger the edit of the first level - the master part of the gridview. However, I cannot trigger the edit on a child gridview.

OnRowEditing="grdChildGridEdit_RowEditing"

The master and the child gridviews have objectdatasources in a markup but I have to do the additional data binding after the loading the control on the parent page (see the code below). I'm doing that additional data binding only for the master gridview that is working fine and shows the data for the master and the child gridviews. When I click the Edit button on the master gridview it shows text boxes for the editing but when I click the Edit button on the child gridview it's doing nothing and moreover the editing mode for the master gridview is going back to the initial stage (labels).

I was trying to trigger it throughuse the registering the event:

[code]....

View 5 Replies

Dynamically Assign Click Event For Anchor Tag In C#?

Feb 26, 2011

i was working on an application where i was having large string and need to be divided in chuck of string, and should be kept in a div, just the purpose was giving pagination to the large string, so i wrote code to split the whole string into multiple chunks and added the chunk of string in a div created at runtime, and also disabled all the other div's except the first, and also given page numbers in the footer for changing pages, but now my issue is i am using anchor tags using HTMLAnchor from code behind, now whenever user clicks on any page that div should be set to display and other all should get hide, i am not getting how should i do this from code behind, i have done everything from code behind, from creating div to hiding div...

View 2 Replies

Load Dynamic Control From A Dropdownlist Event Handler - How To Preserve The Control After Button Event

Mar 10, 2011

I understand I need to load my dynmaic control on every postback and preferrably in Page_Init(). But my dyanmic controls are loaded from a dropdownlist selectedindexchanged event handler. Now after any postback, my dynamic controls are gone. How would I force it to load on every postback ?

View 2 Replies

Web Forms :: Add Event Handler To Dynamically Created Button?

Oct 5, 2010

Does anyone have a good vb example of adding an "onClick" event to a button that is dynamically added into a templatefield of a gridview. MSDN just says to use the addhandler statement with no other good info for a 'dynamic' scenario:

[URL]

View 12 Replies

Adding OnServerClick Event Handler To HtmlAnchor Dynamically

Jan 14, 2010

When I write the code for Each HtmlAnchor a in Me.Master.FindControls("link" + i)
AddHandler e.OnServerClick, AddressOf OnClick
end for
I get an error that OnServerClick event is protected and I cannot access it. The question is how do I dynamically add event handlers to HtmlAnchor controls?

View 2 Replies

VS 2008 - Event Handler For Dynamically Created Button

Jul 31, 2013

I'm dynamically creating a table on my page with rows and controls. It looks like a gridview but it's not (it should've been, but too late now, seriously). I have a first name, last name, date of birth, etc. I want each row to have a button to add rows underneath it. So I create an event handler each time I create a new row and assign it to the click event of a button contained in the row. But it's not getting called.

Is it correct that the event handler doesn't stay established because the buttons are dynically created and are lost when the page posts back?

Code:
ImageButton addDependentButton = new ImageButton();
addDependentButton.ID = ADD_DEPENDENT_BUTTON_ID_BASE + currentSubscriberIDAsString;
addDependentButton.ImageUrl = "/Images/btnAdd.gif";
addDependentButton.Click += new System.Web.UI.ImageClickEventHandler(this.AddDependentButtonByRow_Click);
Control[] addDependentArray = { addDependentButton, addDependentDropDown };
WebControlUtilities.AddMultipleControlCellToRow(currentRow, addDependentArray, Constants.CSS_CLASS_TABLE_TEXT_NORMAL);

View 4 Replies

Web Forms :: Dynamically Add Event Handler To A Button At Run Time

May 7, 2015

I made a dynamic TextBox and a Dynamic Button.. I would like to add an event on Dynamic Button to change the textbox text when clicked. What I want is when I made TextBox1 text "1" into "2" the TextBox having "2" will become "1". below is my code for page2. Page 1 is just a CheckBoxList consist of items to be passed on page2 DropDownList.

 .cs Page2
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

[code]...

View 1 Replies

Web Forms :: Using Dynamically Link Button Creation And Event Handler

Jul 4, 2010

The below shown Tree view are dynamically created link buttons.

These link buttons should be created DYNAMICALLY.

I tried to create dynamically and its working fine for 1 and 2 case.

But I am not able to get 3 case dynamically when i clickon from 2 case.

If I click on Products Link Button it'll display all sub products(i.e, computers, mobiles,...) and

if I click on computers and then only it should display all other sub products like Keyboard, Mouse,...

lly, if I click on Mobiles and then only it should display all other sub products like Nokia, Samsung ,...

etc..

[code]....

View 7 Replies

Dynamically Attached Event Handler Not Working With Update Panel?

Apr 22, 2010

I have a checkbox inside a update panel. Based on certain conditions, I set the autopostback property to true and also attach a event handler as below

chkBox.CheckedChanged += new EventHandler(this.ChkBoxChaned_Click);

But when the checkbox is checked/unchecked, autopostback happens but the event handler does not get hit.

View 1 Replies

Web Forms :: Add Event Handler To User Control And Capture Event On Parent Page?

Apr 24, 2010

Using vb.net/asp.net 2005.

I have a page books.aspx that has a control named authors.ascx.

Inside the authors control there is a "select" button I want to add some kind of listener or event handler (not sure of the correct terminology) so on the parent page (books.aspx) I can respond to the "select" button being clicked.

I have to pass the authorID from the user control to the parent page.

In my authors.ascx control I just created this event:

[Code]....

Now I need to write the function for SelectAuthorBtnClick and I think add some kind of listener in the parent page to listen and handle the event.

View 7 Replies

Difference Between Adding Code In The PreLoad Event Handler And At The Top Of The Load Event Handler?

Oct 3, 2010

Is there a technical reason for the existence of Page.PreLoad or is this just convenience to have a place where you can neatly place code that always have to be executed before the Load code? Is there a difference between adding code in the PreLoad event handler and adding code at the top of the Load event handler? And what would be a typical scenario where you use PreLoad?

View 2 Replies

Web Forms :: How To Add An Event Handler For Dynamically Created Button In Ajax Update Panel

Feb 17, 2010

I have a grid view in Ajax UpdatePanel. In a column of a grid view I have a button call btnAddNewRecord. I need to fire btnAddNewRecord.Click event once I click on that.

How can I do this?

View 4 Replies

Get Id Of Dynamically Added Control?

Jan 29, 2010

i have one html table "table "and added controls it at run time as :

HtmlTableRow tabelrow = new HtmlTableRow();
HtmlTableCell tablecell = new HtmlTableCell();
Label lbl = new Label();
tablecell.Controls.Add(lbl);

then i want to get each controls by using foreach

such as (foreach control c in table.controls) or (foreach control c in tablecell.controls)but its not working.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved