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 ????
-
Are you intending to do this without a Postback? If so, you'll need ASP.NET AJAX (or another similar library) to accomplis this.Anthony– Anthony2009-04-17 16:08:38 +00:00Commented Apr 17, 2009 at 16:08
-
duplicate of (for example): stackoverflow.com/questions/737981/…M4N– M4N2009-04-17 16:11:41 +00:00Commented Apr 17, 2009 at 16:11
-
@Martin: That was about a Textbox! This is about a Label! It's a whole world of difference, man! :PCerebrus– Cerebrus2009-04-17 16:20:39 +00:00Commented Apr 17, 2009 at 16:20
-
1@Cerebrus - you're right about that, adding a textbox might actually be useful!John Rasch– John Rasch2009-04-17 16:24:10 +00:00Commented Apr 17, 2009 at 16:24
6 Answers
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.
Comments
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
});
});
Comments
here a simple solution that might help u . first add a label to the container( eg form, panel, etc) and hide it using the following code:-
label1.hide();
you have to enter the above code in the form_load function then in the button1_click function enter the below code
label1.show();
label1.text="some text";