how to get corresponding label name using textboxname

Posted by Oswaldlily under C# on 12/13/2012 | Points: 10 | Views : 961 | Status : [Member] | Replies : 2
Username(label1) : [textbox1]
Firstname(label2) : [textbox2]
LastName(label3) : [textbox3]



I have similar to this 15 labels and 15 textbox.

using reflection i m getting textbox name indirectly.
if textbox1 is empty,my error should be "Username is empty"
How i should map textbox1 and label1?
if error in control textbox1,how will i know its corresponding
label is Username?




Responses

Posted by: Naraayanan on: 12/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi ,

If (txtUserName.Text == "")

{
MessageBox.Show("Please Enter " + lblUserName.Text + "in the Input Box");
}


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundnani.Rt on: 1/19/2013 [Member] Starter | Points: 25

Up
0
Down
You need to assign the id-names parallely, i.e.

[lbl1..txtBox1]...[lbln..txtBoxn]

Then at any instance, you can track them parallely.

Example:


if(txtBox1.Text ..<some condition>)
MessageBox.Show("<Message> for lbl1");



Similarly,

if(txtBoxn.Text ..<some condition>)

MessageBox.Show("<Message> for lbln");


Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response