I have a user control with a linkbutton_click event loading another user control with a linkbutton_click event of its own. When the second link is clicked, its _click event is skipped. Beyond what the code below what am I missing to have every _click event
captured?
public partial class EditAccount : System.Web.UI.UserControl {
private Page page;
lb.Click += new System.EventHandler(this.LinkButton_Click);
Since you already have an event handler, I don't think you need a new one, I think you casted the event handler to null, so the event handler was not written to the browser in script, at the bottom of the page source code.
Edit:
I don't code in cs, but in vb, I assign the same event handler all the time, but I just use AddHandler. Since I don't have any cs projects that I can use for testing, I can't really check it out.
This might help you use the same event handler, but be able to call different functions depending on which Linkbutton was clicked
It would take a little bit of changing, but you could make properties on your control and use IF statements in the render process to change the rendering of the output. Then, you would not have several separate child controls to contend with.
scott_rider
Member
9 Points
34 Posts
User Control
Apr 11, 2012 08:02 PM|LINK
I have a user control with a linkbutton_click event loading another user control with a linkbutton_click event of its own. When the second link is clicked, its _click event is skipped. Beyond what the code below what am I missing to have every _click event captured?
public partial class EditAccount : System.Web.UI.UserControl {
private Page page;
override protected void OnInit(EventArgs e) {
this.page = (Page)HttpContext.Current.Handler;
this.Controls.AddAt(0, CreateLinkButton("save20", "Save Account", "save_account", "20"));
}
protected void Page_Load(object sender, EventArgs e) { }
private void LinkButton_Click(object sender, EventArgs e) {
this.page.FindControl("right_form_section").Controls.Clear();
RaiseBubbleEvent(this, new CommandEventArgs(((LinkButton)sender).CommandName, ((LinkButton)sender).CommandArgument));
}
protected override bool OnBubbleEvent(object source, EventArgs args) {
RaiseBubbleEvent(this, new CommandEventArgs(((LinkButton)source).CommandName, ((LinkButton)source).CommandArgument));
return true;
}
public LinkButton CreateLinkButton(string Id, string Text, string CommandName, string CommandArgument) {
LinkButton lb = new LinkButton();
lb = new LinkButton();
lb.ID = Id;
lb.Text = Text;
lb.CommandName = CommandName;
lb.CommandArgument = CommandArgument;
lb.Click += new System.EventHandler(this.LinkButton_Click);
return lb;
}
}
scott_rider
Member
9 Points
34 Posts
Re: User Control
Apr 12, 2012 06:46 PM|LINK
I know I am missing something. Is there not enough information for anybody to help?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: User Control
Apr 13, 2012 02:14 AM|LINK
What's the "right_form_section"?
scott_rider
Member
9 Points
34 Posts
Re: User Control
Apr 14, 2012 03:18 AM|LINK
An id for a div in a web page.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: User Control
Apr 14, 2012 05:21 AM|LINK
Hello:)
Would you mind sending your whole proj related to that only to v-dedong@microsoft.com for more analyses?
Reguards!
Plz attach the URL of the issue……
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: User Control
Apr 16, 2012 03:08 AM|LINK
Sorry I've run you app and it seems that your error means this:
'IntraFluxCMS.Frame' is not allowed here because it does not extend class 'System.Web.UI.Page'.
jkirkerx
Contributor
3750 Points
873 Posts
Re: User Control
Apr 20, 2012 10:15 PM|LINK
lb.Click += new System.EventHandler(this.LinkButton_Click);
Since you already have an event handler, I don't think you need a new one, I think you casted the event handler to null, so the event handler was not written to the browser in script, at the bottom of the page source code.
Edit:
I don't code in cs, but in vb, I assign the same event handler all the time, but I just use AddHandler. Since I don't have any cs projects that I can use for testing, I can't really check it out.
This might help you use the same event handler, but be able to call different functions depending on which Linkbutton was clicked
http://stackoverflow.com/questions/750541/passing-a-param-to-system-eventhandler-in-c-sharp
jasoncmcg
Member
7 Points
6 Posts
Re: User Control
Sep 27, 2012 08:05 PM|LINK
This article shows the benefit of writing directly to the html output that you need.
http://msdn.microsoft.com/en-us/library/aa479016.aspx
It would take a little bit of changing, but you could make properties on your control and use IF statements in the render process to change the rendering of the output. Then, you would not have several separate child controls to contend with.