Tutorials
Resources
Forum
Interview
Jobs
Projects
Offshore Development
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Revenue Sharing
|
Talk to Us
|
My Profile
Sign In
Register
AdSense Revenue
Gifts
Active Members
Today
Athira Appukut...
(278)
vipul
(175)
D.Jeya kumar(J...
(143)
Last 7 Days
Athira Appukut...
(1737)
D.Jeya kumar(J...
(1341)
Sridhar R
(1336)
more...
Add contol on page and handle them at RunTime.
Posted Date: 25 Jun 2008 Resource Type:
Tips
Category:
Visual Studio
Posted By:
Subodh kumar Prajapati
Member Level:
Gold
Rating:
Points
: 10
Sometimes wee need to create a runtime contols. In dot net it is very easy to create them. You can create a control and add at runtime as follows:
Step1:
Declare a control as globaly for that page. Because if you are not declare that control as globaly then you can't access them in another funtion scope.
Button bttchk=new Button();
Step2:
Now you can provide there id and value at any event of controls of page. Like if you want to create the control at page load time, then you can write them as follows:
bttchk.id="MybttId"; // provide the id of button.
bttchk.Text="Runtime Button"; // Set the text of button.
bttchk.ToolTip="Runtime Created"; // Set the tooltip of button.
// LIke this you can set another properties of this button control. like : back color, forcolor , style etc.
Step3:
Now most important thing : How to work on click of this button. So for this add the following line of code:
// Set the click event of button.
bttchk.Click+=new EventHandler(bttchk_Click);
// Now add this "bttchk" button on page as follows:
Page.Form.Controls.Add(bttchk);
Now question is arising that what is "bttchk_click". Actualy this is a function which will be call on this button click. You can write this function as below:
protected void bttchk_Click(object sender, EventArgs e)
{
// At this place you can perform any action which you want.
//Here I am create a new textbox control on "bttchk" button click.
TextBox txt = new TextBox(); // Create a new textbox.
txt.Text = bttchk.Text; // Set the text of textbox control as bttchk button contol name.
Page.Form.Controls.Add(txt); // Now add this contol on page.
}
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
(No tags found.)
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
TextBox Mode
Previous Resource:
Tips for Data Replication
Return to Discussion Resource Index
Post New Resource
Category:
Visual Studio
Post resources and
earn money
!
Related Resources
Useful shortcuts in VS.NET
Asp.Net Web Deployment options( When to use what )
Shortcut to colapse and expand regions
Source code File name and line number
Shoft key
dotNet Slackers
BizTalk Adaptors
Web Design
silicone halloween mask
Contact Us
Privacy Policy
Terms Of Use