Thursday, November 17, 2011

Create dynamic control using c#

Here i will create two text boxes and one hyperlink dynamically using csharp.Whenever create a new server control in code behind we have to instantiated for each server control.The properties of each control will be given by using the object of control

Default.aspx:
<html><head></head>
<body>
<asp:label id="lbl" runat="server" ></asp:label> 
</body>
</html>

Defalut.aspx.cs:
textbox t1=new textbox();
t1.Id="txtname";
//set textmode propety
t1.TextMode = TextBoxMode.MultiLine;
this.controls.add(t1);
textbox2 t2=new textbox();
t2.id="txtpas";
this.controls.add(t2);
button bt=new button();
bt.id="hyp";
bt.text="submit";
this.controls.add(bt);
Hyperlink h1=new Hyperlink();
h1.id="hyp";
h1.NavigateUrl="test.aspx";
this.controls.add(hyp);

No comments:

Bel