In the Page_Load method I create a couple of controls, based on various conditions. I would like to register server side code with those controls. However, for the last part I need to declare my controls as server controls. This is normally done by runat=server, but I don't know how to set this attribute in the C# code. myControl.Attributes.Add("runat", "server") does not do the trick. This one works, meaning that the "test" method is called when I click on it:
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="test">testtext</asp:LinkButton>
This one does not work:
LinkButton lb = new LinkButton();
lb.ID = "LinkButton1";
lb.OnClientClick = "test";
lb.Text = "testtext";
lb.Attributes.Add("runat", "server");
I can click on it, and the page is loaded, but the test-method is not called.
Any hints?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…