Reputation: 2960
The page has table inside updatePanel and linkbutton inside tablecell:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Table ID="Table1" runat="server" BackColor="White" BorderColor="Black"
BorderWidth="1px" ForeColor="Black" GridLines="Both" BorderStyle="Solid">
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
Inside .cs file I add rows to the table:
TableRow tr = new TableRow();
TableCell tc = new TableCell();
LinkButton lb = new LinkButton();
lb.Text = "Click me";
lb.Click += new EventHandler(this.LinkButton_Click);
tc.Controls.Add(lb);
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
And the method:
protected void LinkButton_Click(Object sender, EventArgs e)
{
Response.Write("<script type='text/javascript'>");
Response.Write("alert('Ok!');");
Response.Write("</script>");
}
So, when I click linkbutton the alert doesn't work. What is a problem?
Note that, if I delete updatepanel the linkbutton works when clicking at it.
Upvotes: 0
Views: 1679
Reputation: 1410
You need to add postbacktrigger as following:
<asp:PostBackTrigger ControlID="SearchBrn"/>
Upvotes: 0
Reputation: 810
It is not the correct way
Use this
ScriptManager.RegisterStartupScript(pnlUpdateCom, this.GetType(), "UpdateCom", "alert('OK!.');return false;", true);
Upvotes: 2