ASP.Net में टेक्स्ट बॉक्स कण्ट्रोल का प्रयोग

ASP.Net में टेक्स्ट बॉक्स कण्ट्रोल का प्रयोग (TextBox Control in ASP.Net)

TextBox Control एक आयताकार बॉक्स (Rectangle Box) होता है जिसका उपयोग यूजर इनपुट लेने के लिए किया जाता है। सरल शब्दों में TextBox एक ऐसी जगह है जहाँ यूजर asp.net वेब फॉर्म पर कुछ टेक्स्ट इनपुट कर सकते हैं। TextBox Control asp.net में सबसे उपयोगी वेब सर्वर Control है। TextBox बनाने के लिए या तो हम कोड लिख सकते हैं या Visual Studio IDE के ड्रैग एंड ड्रॉप सुविधा का उपयोग कर सकते हैं।

Syntax of ASP.Net TextBox

<asp:TextBoxID=”TextBox1”runat=”server”></asp:TextBox>

सर्वर इसे HTML control के रूप में प्रस्तुत करता है और ब्राउज़र के लिए निम्न कोड प्रदान करता है।

<input name=”TextBox1″ id=”TextBox1″ type=”text”>

Text Box Properties

सभी सर्वर साइड कंट्रोल की अपनी properties और events होते हैं। नीचे दी गई सूची टेक्स्टबॉक्स प्रॉपर्टीज को दर्शाती है।

Properties Description
ID Identification name of textbox control.
Text It is used to display text in a control.
BackColor It is used to set background color of textbox control.
ForColor It is used to set text color of the control.
ToolTip It displays a text on control when mouse over on it.
TabIndex It is used manage tab order of control.
CssClass It is used to apply style on control.
Enable true/false – used to enable or disable control.
Enable Theming true/false – It is used to enable or disable effect of theme on control.
CausesValidation true/false – It is used to enable or disable validation effect on control
Visible true/false – It is used to hide or visible control on web page.
Important Properties of TextBox control
MaxLenght It is used to set maximum number of characters that can be input in TextBox.
TextMode Single / Multiline / Password
ReadOnly true/false – used to enable or disable control readonly.

Set Properties? (प्रॉपर्टीज कैसे सेट करे?)

ASP.Net में हम Properties को दो तरीको से सेट कर सकते है|

Design Time – जब आप Develop कर रहे हो, Design कर रहे हो या Coding कर रहे हो उसे Design Time कहाँ जाता है|


Run time – जब आप कोडिंग को Run करते हो तो उसे Run Time कहा जाता है|

Example –

  • TextBox1.Backcolor=System.Drawing.Color.Yellow;
  • TextBox1.BorderStyle=BorderStyle.Solid;
  • TextBox1.BorderColor=System.Drawing.Color.Red;
  • TextBox1.BorderWidth=3;
  • TextBox1.ForeColor=System.Drawing.Color.Green;
  • TextBox1.Font.Bold=True;
  • TextBox1.MaxLength=10;
  • TextBox1.TextMode=TextBox.Password;

Methods

हर कण्ट्रोल में तीन चीजें होती है|

  1. Properties
  2. Methods
  3. Events

2. TextBox Methods

Focus– टेक्स्टबॉक्स पर कर्सर सेट करने के लिए।

ToString– Textbox content को स्ट्रिंग में बदलने के लिए|

3. TextBox Events


इवेंट में सिर्फ TextChange का यूज किया जाता है| यह तब चलता है जब हम वैल्यू को चेंज करते है|

How to use TextBox in ASP.Net

Step 1 – Visual Studio खोलें -> एक नया खाली वेब एप्लिकेशन बनाएं।

Step 2 – टेक्स्टबॉक्स उदाहरण के लिए एक नया वेब पेज बनाएं।

Step 3 – Toolbox से वेब पेज पर टेक्स्टबॉक्स कण्ट्रोल को Drag and drop करें|

Step 4 – Control की ID Property सेट करें – जैसे: txtname, txtcity, txtmobile

Step 5 – टेक्स्ट को control करने या control से text प्राप्त करने के लिए उपयोग की जाने वाली Text property का प्रयोग करे|


error: Content is protected !!