I am implementing a website using ASP.NEt 2.0 and I want to add a new Label when I press an existing button Could some body help me on doing this ????
you need to create new instance of lable then add your label control by using control.add(lable1) in pre-existing button event.
it will add your label on page, whenever you hit pre-existing button.
in the OnClick event for the button:
Label lbl = new Label();
lbl.Text = "some text";
ControlContainingLabel.Controls.Add(lbl);
You can create a label using Syed Tayyab Ali's answer, however if someone clicks another button and you get another postback, your first created label will disappear as the page will be recreated from scratch.
If the button doesn't depend on what is going in the text of the label, or the server is not updating with info too display in label then there is no reason to add it on the server side. you can easily put the label where you want in your client side code and use some form of javascript (jQuery) to hide it and when the button is clicked then unhide the label as so:
$(function(){
$('.label1').hide(); //hide the label with the class name label1
$('.button1').click(function(){ // bind the button's click event
$('.label1').show(); //unhide the label
});
});
Label lbl = new Label(); lbl.Text = "some text";
ControlContainingLabel.Controls.Add(lbl);
จากโค้ดนี้ค่ะ อยากจะกำหนดตำแหน่งที่จะให้ label lbl แสดงค่ะ ต้องเขียนโค้ดอะไรเพิ่มคะ