Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net button/linkbutton webcontrol dynamically added in bootstrap modal body doesn't postback

I have added linkbutton inside html table dynamically and add into bootstrap modal's body. (linkbutton has coded linkbutton.click += new eventhandler(Eventclick1);)

enter image description here

but, when I click on select, it won't go to my function Eventclick1. It just refreshes the whole page. (it is already inside updatepanel). Anyways I can make the select button to postback? (I don't want to add client side click function like onclientclick = $('#otherbutton').click(); )

UPDATE

lnk_button.ID = this.ID + "AuditSelectedRow_" + Convert.ToString(l_loop); 
lnk_button.Click += new EventHandler(OnAuditRowSelected);
lnk_button.Text = "Select"; 
WebControl wc_tdSelect = new WebControl(HtmlTextWriterTag.Td); 
wc_tdSelect.Controls.Add(lnk_button);
like image 901
Min Hong Tan Avatar asked May 07 '15 04:05

Min Hong Tan


1 Answers

First make sure that your custom webcontrol inside Updatepanel still exist at the end of page life cycle. I assume you are calling a function where you are adding linkbutton to the webcontrol. something like this:

// Custom function Creating link buttons

private void CreateControls() {

// Create your link buttons here.

}

Now try calling the same function again inside page pre-init method which ensures that the control still exist at the time of button click event. something like this:

//Page Pre Init
protected void Page_PreInit(object sender, EventArgs e)
{
CreateControls();
}

Make sure you have your web control added to updatepanel inside the same function as listed above. Here is a sample code attaching webcontrol to the updatepanel.

yourUpdatePanel.ContentTemplateContainer.Controls.Add(wc_tdSelect);

I am sure you will have your desired result this time :)

like image 111
prashantchalise Avatar answered Nov 08 '22 06:11

prashantchalise