This is a migrated thread and some comments may be shown as answers.

How to caculate the Radmasked textbox length

9 Answers 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Priyanka
Top achievements
Rank 1
Priyanka asked on 15 Apr 2013, 10:41 AM

Hi Telerik team,

We have used the RadMasked textbox control for home phone number field of Standard mask type.(___-___-____) which allow 10 digits home phone number and I want to calculate the Radmasked textbox length in coded step.

I have write the following code in script test.

object objhomephone= GetExtractedValue("RmtbHomePhoneNumberText");
int homephone= Convert.ToInt16(objhomephone.ToString().Length);
System.Windows.Forms.MessageBox.Show(homephone.ToString());

I m getting length 12 in message box without entering any digits in home phone number field.
How should i calculate the exact number of digits entered in the rad masked textbox??? 


Thanks,

9 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 15 Apr 2013, 11:22 AM
Hi Priyanka,

You can use following code:

string number = RmtbHomePhoneNumber.TextBoxValue.Length.ToString();
 
"Number" will contain the number of characters in the RadMaskedTextBox.

If I am missing something please give us more detailed information about your scenario.

A Jing video demonstration may also help us to better understand what you want to achieve exactly.

Hope to hear from you soon.

All the best,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Priyanka
Top achievements
Rank 1
answered on 16 Apr 2013, 05:41 AM

Hi Boyan Boev,
I want to calculate length in coded step.
I am extracting the radmasked textbox value using object in coded step
object objhomephone= GetExtractedValue("RmtbHomePhoneNumberText"); where RmtbHomePhoneNumber is DataBindVariableName, i didn't get the RmtbHomePhoneNumber.TextBoxValue property.
SO please help me to find out the solutions for these.

thanks,

0
Boyan Boev
Telerik team
answered on 17 Apr 2013, 11:56 AM
Hi Priyanka,

I wrote a sample code against our demo site.

If you want to use extracted value, you need to set it first. You don't need to use object also:

RadInput textbox = Manager.Current.ActiveBrowser.Find.ById<RadInput>("ctl00_ContentPlaceHolder1_RadTextBox1_wrapper");
textbox.TypeText("asdfg", 50, 50, false, false);
SetExtractedValue("objhomephone", textbox.TextBoxValue.Length);
Log.WriteLine(GetExtractedValue("objhomephone").ToString());

I recorded a short video with the entire process.

Hope this helps. 

Regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Priyanka
Top achievements
Rank 1
answered on 18 Apr 2013, 12:11 PM

Hi  Boyan Boev,
I can't able to see the video which you have been recorded, actually it displays the blank page.
As you said, i have use the same code in my test project but it gives the "Object reference not set to an instance of an object." error..
Previously, i have use the some code and it gives me the same error on first line itself thats the reason i used the object because i think i am passing the wrong control/field Id in following code line.

RadInput textbox = Manager.Current.ActiveBrowser.Find.ById<RadInput>("ctl00_ContentPlaceHolder1_RadTextBox1_wrapper");

For you information , i am passing the control id using page view source.
Can you please tell, from where i get the exact page control id???
And if possible, can i see the previously recorded video.???

Thanks,

0
Boyan Boev
Telerik team
answered on 19 Apr 2013, 02:20 PM
Hello Priyanka,

Attaching the video to this ticket. 

You can get the ID of some element via F12 developer tools (press F12 to launch it) in Internet explorer for example (see the attached screen shot).

Note that the base class of all HTML elements is HtmlControl, the base class of DOM elements is Element. However if you are using a wrong ID you will be not able to locate the control.

Hope to hear from you soon.

Greetings,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Priyanka
Top achievements
Rank 1
answered on 22 Apr 2013, 06:50 AM
Hi Boyan boev,

I have use the same code for radinput control to check whether it is working properly or not for radinput instead of Radmasked textbox but same  exception is thrown "Object reference not set to an instance of an object."
I have written the following code.
             RadInput input= ActiveBrowser.Find.ById<RadInput>("rtbPatientFirstName");
            input.TypeText("Priya");
            string inputvalue= input.TextBoxValue;
            Log.WriteLine(inputvalue);
As you advised, i have passed the control id using F12 developer tools.
Please find the attached images which gives you the brief idea.

Thanks
0
Boyan Boev
Telerik team
answered on 23 Apr 2013, 03:09 PM
Hello Priyanka,

Since this is a duplicate of your public forum post, let's continue the discussion there.
 

All the best,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Priyanka
Top achievements
Rank 1
answered on 30 Apr 2013, 06:29 AM
Hi Boyan Boev,

I have find the solution to calculate the length for rad masked textbox using object.


homephone= GetExtractedValue(
"RmtbHomePhoneNumberText");

string homephonetext= homephone.ToString().Remove(3,1);

string home=homephonetext.Remove(6,1);

 String sphome=System.Text.RegularExpressions.Regex.Replace(home,"_","");

int home_length= sphome.Length;

System.Windows.Forms.MessageBox.Show(home_length.ToString());

Using above code, i have get the expected value but i am not satisfied with this solution as unnecessarly it increases the LOC.

As you said, i have use the same code which you have replies me but still getting the, "Object reference not set to an instance of an object." exception using following code line.

 RadInput textbox = Manager.Current.ActiveBrowser.Find.ById<RadInput>("rmtbHomePhoneNumber");

By the thanx for your valuable guidance.
Thanx.......

 

0
Boyan Boev
Telerik team
answered on 01 May 2013, 03:48 PM
Hello Priyanka,

I am glad to hear that this code works for you! Thanks for the update. 

In order to find a better solution we need access to your application.

If it is not possible to grant us access to your application, please take a Fiddler trace and attach it to a support ticket in a zip file. You can capture a Fiddler trace using FiddlerCap.  

Greetings,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Priyanka
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Priyanka
Top achievements
Rank 1
Share this question
or