Victor Charles
asked on
Help with Formating Text Box
Hello,
I am using the code below to force users to enter text in a TextBox in the following format: xx,xxx.
1. How do I modify the code, to alert the users as soon as they don't meet the format during a key press event or
when they leave the control and try to populate other fileds?
2. How do I Mask my TextBox as Follows A_B_C_D_ where _ is where they can only enter numbers? and also trigger an alert if the format is not followed?
I will need to Reterive the entire text, For example A1B2C3D4, not just the numbers they enter.
<asp:RequiredFieldValidato r ID="RequiredFieldValidator 1" runat="server" ControlToValidate="TextBox 1"
Display="Dynamic" ErrorMessage="Required"></ asp:Requir edFieldVal idator>
<asp:RegularExpressionVali dator ID="RegularExpressionValid ator1" runat="server"
ErrorMessage="Invalid Format (xx,xxx)" ValidationExpression="\d{2 },\d{3}" ControlToValidate="TextBox 1"
Display="Dynamic"></asp:Re gularExpre ssionValid ator>
Thanks,
Victor
I am using the code below to force users to enter text in a TextBox in the following format: xx,xxx.
1. How do I modify the code, to alert the users as soon as they don't meet the format during a key press event or
when they leave the control and try to populate other fileds?
2. How do I Mask my TextBox as Follows A_B_C_D_ where _ is where they can only enter numbers? and also trigger an alert if the format is not followed?
I will need to Reterive the entire text, For example A1B2C3D4, not just the numbers they enter.
<asp:RequiredFieldValidato
Display="Dynamic" ErrorMessage="Required"></
<asp:RegularExpressionVali
ErrorMessage="Invalid Format (xx,xxx)" ValidationExpression="\d{2
Display="Dynamic"></asp:Re
Thanks,
Victor
ASKER
Hello,
I tried the following but I'm getting a compilation error message, can you please help me with the proper javascript format.
Code in Header tag:
<script type="text/javascript" id="Validate" runat =server>
function validate() {
<asp:RequiredFieldValidato r ID="RequiredFieldValidator 1" runat="server" ControlToValidate="TextBox 1"
Display="Dynamic" ErrorMessage="Required"></ asp:Requir edFieldVal idator>
<asp:RegularExpressionVali dator ID="RegularExpressionValid ator1" runat="server"
ErrorMessage="Invalid Format (xx,xxx)" ValidationExpression="\d{2 },\d{3}" ControlToValidate="TextBox 1"
Display="Dynamic"></asp:Re gularExpre ssionValid ator>
};
</Script>
Code in Form tag:
<asp:TextBox ID="TextBox1" runat="server" onblur = "Validate()"></asp:TextBox >
I tried the following but I'm getting a compilation error message, can you please help me with the proper javascript format.
Code in Header tag:
<script type="text/javascript" id="Validate" runat =server>
function validate() {
<asp:RequiredFieldValidato
Display="Dynamic" ErrorMessage="Required"></
<asp:RegularExpressionVali
ErrorMessage="Invalid Format (xx,xxx)" ValidationExpression="\d{2
Display="Dynamic"></asp:Re
};
</Script>
Code in Form tag:
<asp:TextBox ID="TextBox1" runat="server" onblur = "Validate()"></asp:TextBox
You have put asp.net validators in javascript. I thought you want to do custom validation
ASKER
What should I include in the Javascript section to enforce the format that I want using onblur?
You can use some string manipulation or regular expressions etc.
http://www.javascriptkit.com/javatutors/re.shtml
http://www.javascriptkit.com/javatutors/re.shtml
ASKER
Hi,
Thaks for the link, unfortunately it didn't help sokve the issue. I have two primary goals,
1, How do I force the users to Enter "A" (0-9) B (0-9)(0-9)C (0-9) G(0-9) For example: A1B36C8D8
2. How do I force the users to Enter ( 4 Didits) (Dash) (Three digits)(Dash)(4Digts) For example:
1206-00-027-3767
Victor
Thaks for the link, unfortunately it didn't help sokve the issue. I have two primary goals,
1, How do I force the users to Enter "A" (0-9) B (0-9)(0-9)C (0-9) G(0-9) For example: A1B36C8D8
2. How do I force the users to Enter ( 4 Didits) (Dash) (Three digits)(Dash)(4Digts) For example:
1206-00-027-3767
Victor
I think your best bet is to use a Masked Textbox.
ASKER
I don't see it in my ToolBox, does it come with VS2010 professional version?
Its part of AJAX library
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx
ASKER
i AM TRYING TO INSTALL THE ajax EXTENSION BUT SO FAR NO LUCK, ANY HELP FROM YOU WOULD BE GREATLY APPRECIATED.
Download the correct version for your .NET framework, install it, then reference the DLLs. Which step are you stuck at?
ASKER
I installed the Ajax extension library, but I don't see it in my toolbox or can't see in the section where I can choos the controls.
ASKER
Hi again,
Does the Masked edit box have a datasource property? I need to bound it to a data source to view the data in my xml files.
Does the Masked edit box have a datasource property? I need to bound it to a data source to view the data in my xml files.
The maskededitbox itself wont have a datasource. Datasource will be set on the container (repeater, grid etc) level and then you can add databindings on the textbox level.
ASKER
I can set the datasource to a Grid, can you please send me an example on how to use databindings on the textbox level. I will load my combobox with multiple records but will remove thre trigger for users no to see all the data at once, they will need to click the Nex/Previous buttons to move through the records, I wanted to use a combobox, but I can't format it to force users to enter data in a certain format.
ASKER
I can set the datasource to a Grid, can you please send me an example on how to use databindings on the textbox level. I will load my combobox with multiple records but will remove thre trigger for users no to see all the data at once, they will need to click the Nex/Previous buttons to move through the records, I wanted to use a combobox, but I can't format it to force users to enter data in a certain format.
Use the Text property of the maskedtextbox.
ASKER
Hi,
I used the following code, but nothing appears in the textbox:
Repeater1.DataSource = dtDonor
' Repeater1.DataMember = "Countryorigin"
C1Manufacturer.Text = Repeater1.DataSource
How do you properly connect the Textbox control with the repeater datasource?
I used the following code, but nothing appears in the textbox:
Repeater1.DataSource = dtDonor
' Repeater1.DataMember = "Countryorigin"
C1Manufacturer.Text = Repeater1.DataSource
How do you properly connect the Textbox control with the repeater datasource?
ASKER
Correction with code:
Repeater1.DataSource = dtDonor
Repeater1.DataMember = "Countryorigin"
Repeater1.Databind()
C1Manufacturer.Text = Repeater1.DataSource
Repeater1.DataSource = dtDonor
Repeater1.DataMember = "Countryorigin"
Repeater1.Databind()
C1Manufacturer.Text = Repeater1.DataSource
ASKER
Hi,
I tried to follow the example by using the code below, but the C1manufacturer Textbox control still doesn't display the data. Can you please help me come up with the proper code.
ASPX File:
<asp:Repeater ID="RepeatControl" runat="server">
<ItemTemplate>
DataBinder.Eval(Container. DataItem," CountryOri gin_ID")
C1manufacturer.Text="<%#Da taBinder.E val(Contai ner.DataIt em, "CountryOrigin")%>"
</ItemTemplate>
</asp:Repeater>
Vb File Search Button:
RepeatControl.DataSource = dtDonor
RepeatControl.DataBind()
I tried to follow the example by using the code below, but the C1manufacturer Textbox control still doesn't display the data. Can you please help me come up with the proper code.
ASPX File:
<asp:Repeater ID="RepeatControl" runat="server">
<ItemTemplate>
DataBinder.Eval(Container.
C1manufacturer.Text="<%#Da
</ItemTemplate>
</asp:Repeater>
Vb File Search Button:
RepeatControl.DataSource = dtDonor
RepeatControl.DataBind()
My goodness. Try
<asp:Repeater ID="RepeatControl" runat="server">
<ItemTemplate>
<asp:Textbox id="C1manufacturer" Text="<%#DataBinder.Eval(C ontainer.D ataItem, "CountryOrigin")%>" />
</ItemTemplate>
</asp:Repeater>
<asp:Repeater ID="RepeatControl" runat="server">
<ItemTemplate>
<asp:Textbox id="C1manufacturer" Text="<%#DataBinder.Eval(C
</ItemTemplate>
</asp:Repeater>
ASKER
I tried your code but still no data in my Textbox control, below is my code and also in part B, the code for dsiplaying the data in a combobox.
<asp:Repeater ID="RepeatControl" runat="server">
<ItemTemplate>
<asp:Textbox id="C1manufacturer" Text="<%#DataBinder.Eval(C ontainer.D ataItem, "CountryOrigin")%>"/>
</ItemTemplate>
</asp:Repeater>
Button Click event:
RepeatControl.DataSource = dtDonor
RepeatControl.DataBind()
************************** ***888
Part B:
C1FuzeA.DataSource = dtDonor
C1FuzeA.DataTextField = "CountryOrigin"
C1FuzeA.DataValueField = "CountryOrigin_ID"
C1FuzeA.DataBind()
<asp:Repeater ID="RepeatControl" runat="server">
<ItemTemplate>
<asp:Textbox id="C1manufacturer" Text="<%#DataBinder.Eval(C
</ItemTemplate>
</asp:Repeater>
Button Click event:
RepeatControl.DataSource = dtDonor
RepeatControl.DataBind()
**************************
Part B:
C1FuzeA.DataSource = dtDonor
C1FuzeA.DataTextField = "CountryOrigin"
C1FuzeA.DataValueField = "CountryOrigin_ID"
C1FuzeA.DataBind()
You need to set the datasource of the repeater similar to what you did for drop down.
ASKER
Not sure what you mean, The Repeater Control.DataSource is set to DtDonor , similar to the Combobox, but it doesn't have a datatextField or dataValuefield property.
Oh yeah I missed that. I am at a loss now. Do you have teamviewer?
ASKER
I don't have teamviewer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you , will test your code and get backup you.
ASKER
Thanks You!
http://ajondeck.net/post/2008/07/09/javascript-validate-textbox-onblur.aspx
http://stackoverflow.com/questions/2384266/asp-net-textbox-onblur-event