I have a gridview that c# is trying to pull code over from. For some reason it is not pulling the data of textboxs over here is an example of some of my asp.net:
var text1 = (TextBox)dtlEmployees.FindControl("TextBox1") as TextBox;
txt1 = text1.ToString();
dummy = txt1;
if ((r.IsMatch(txt1)) && (dummy.Length < 36))
{
insert1 = txt1;
}
else
{
Label13.Visible = true;
Label13.Text = "*Please Enter Only Letters In for First Name and less than 35 Chacters*";
break;
}
carnalim
0 Points
28 Posts
.FindControl("TextBox1")
Dec 05, 2012 07:55 PM|LINK
Hello,
I have a gridview that c# is trying to pull code over from. For some reason it is not pulling the data of textboxs over here is an example of some of my asp.net:
<asp:DetailsView id="dtlEmployees" Visible="False" DataKeyNames="EmployeeID" DefaultMode="Edit" DataSourceID="srcNames2" AutoGenerateRows="False" GridLines="None" Runat="server" > <Fields> <asp:TemplateField HeaderText="First Name:"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox> </EditItemTemplate>Here is some of the C# (has regex for validation)
var text1 = (TextBox)dtlEmployees.FindControl("TextBox1") as TextBox; txt1 = text1.ToString(); dummy = txt1; if ((r.IsMatch(txt1)) && (dummy.Length < 36)) { insert1 = txt1; } else { Label13.Visible = true; Label13.Text = "*Please Enter Only Letters In for First Name and less than 35 Chacters*"; break; }My text boxes are being filled with:
txt1 = System.Web.UI.WebControls.TextBox
UstesG
Contributor
2172 Points
466 Posts
Re: .FindControl("TextBox1")
Dec 05, 2012 08:02 PM|LINK
change txt1 = text1.ToString(); to txt1 = text1.Text.ToString();
But don't expect me to do your job!
carnalim
0 Points
28 Posts
Re: .FindControl("TextBox1")
Dec 05, 2012 08:08 PM|LINK
Alright it now shows the txt1 = Ryan (for example)
but its still throwing an error with my regex:
Regex r = new Regex("^[a-zA-Z]*$");UstesG
Contributor
2172 Points
466 Posts
Re: .FindControl("TextBox1")
Dec 05, 2012 08:11 PM|LINK
what error?
But don't expect me to do your job!
carnalim
0 Points
28 Posts
Re: .FindControl("TextBox1")
Dec 05, 2012 08:12 PM|LINK
It doesn't pass the if statment. Its getting a false reading. (not passing the regex test)
UstesG
Contributor
2172 Points
466 Posts
Re: .FindControl("TextBox1")
Dec 05, 2012 08:48 PM|LINK
try:
public bool IsAllLetters(string input) { return Regex.IsMatch(input, "^[a-zA-Z]+$"); }But don't expect me to do your job!
oned_gk
All-Star
36022 Points
7355 Posts
Re: .FindControl("TextBox1")
Dec 05, 2012 09:41 PM|LINK
Suwandi - Non Graduate Programmer