Hi all,
I need to create a page that dynamically creates between 1 and about 30 RadNumericTextBoxes on a page. I have no problem with this but I need to assign a onKeyPress event to the dynamically created controls. The javascript in the onKeyEvent needs to check the value in the RadNumericTextBox is 1 digit and NOT a 1, if so tab to the next control. If it is a 1 allow one more digit to be entered and then tab to the next control.
I have spent a while trying to resolve this but to no joy and to be honest I am not quite sure what state my code is currently in!
Anyway, has anyone got any ideas about how to do this or has done it before?
Not sure what use my code is as its probably not in its previously semi-working state, but here goes:
Any help appreciated, ta.
I need to create a page that dynamically creates between 1 and about 30 RadNumericTextBoxes on a page. I have no problem with this but I need to assign a onKeyPress event to the dynamically created controls. The javascript in the onKeyEvent needs to check the value in the RadNumericTextBox is 1 digit and NOT a 1, if so tab to the next control. If it is a 1 allow one more digit to be entered and then tab to the next control.
I have spent a while trying to resolve this but to no joy and to be honest I am not quite sure what state my code is currently in!
Anyway, has anyone got any ideas about how to do this or has done it before?
Not sure what use my code is as its probably not in its previously semi-working state, but here goes:
private void DrawResultsTable(DataView EntrantsResultsData) | |
{ | |
if (EntrantsResultsData != null) | |
{ | |
int HoleCount = EntrantsResultsData.Count; | |
int RowCount = Convert.ToInt16(HoleCount / 9); | |
int LeftOverCells = Convert.ToInt16(HoleCount % 9); | |
int MinCells = HoleCount > 9 ? 9 : HoleCount; | |
TableRow ResultsRow; | |
TableCell ResultsCell; | |
RadNumericTextBox ResultsRadNumericText; | |
int DataIndex; | |
for (int i = 0; i < RowCount; i++) | |
{ | |
ResultsRow = new TableRow(); | |
ResultsRow.CssClass = EntryRowCssClass; | |
for (int y = 0; y < MinCells; y++) | |
{ | |
DataIndex = i * 9 + y; | |
ResultsCell = new TableCell(); | |
ResultsCell.Text = EntrantsResultsData.Table.Rows[DataIndex]["Ordinal"].ToString() + ":"; | |
ResultsCell.CssClass = EntryLabelCellCssClass; | |
ResultsCell.Attributes["align"] = "right"; | |
ResultsRow.Cells.Add(ResultsCell); | |
ResultsCell = new TableCell(); | |
ResultsCell.CssClass = EntryNumericTextBoxCellCssClass; | |
ResultsRadNumericText = new RadNumericTextBox(); | |
ResultsRadNumericText.Type = NumericType.Number; | |
ResultsRadNumericText.ID = "EntrantHoleResult" + EntrantsResultsData.Table.Rows[DataIndex]["Ordinal"].ToString(); | |
ResultsRadNumericText.Text = EntrantsResultsData.Table.Rows[DataIndex]["Score"].ToString(); | |
ResultsRadNumericText.ClientEvents.OnKeyPress = "SendTab(this, 'EntrantHoleResult12',event);"; | |
ResultsRadNumericText.Width = 14; | |
ResultsRadNumericText.MinValue = 1; | |
ResultsRadNumericText.MaxValue = 19; | |
ResultsRadNumericText.MaxLength = 2; | |
ResultsRadNumericText.NumberFormat.DecimalDigits = 0; | |
ResultsRadNumericText.CssClass = EntryTextBoxCssClass; | |
ResultsRadNumericText.ShowSpinButtons = false; | |
ResultsCell.Text = ResultsRadNumericText.ClientID; | |
ResultsCell.Controls.Add(ResultsRadNumericText); | |
ResultsRow.Cells.Add(ResultsCell); | |
} | |
EntrantsResultsTable.Rows.Add(ResultsRow); | |
} | |
ResultsRow = new TableRow(); | |
ResultsCell = new TableCell(); | |
ResultsCell.Text = "<br />"; | |
ResultsCell.ColumnSpan = (MinCells * 2); | |
ResultsRow.Cells.Add(ResultsCell); | |
EntrantsResultsTable.Rows.Add(ResultsRow); | |
ResultsRow = new TableRow(); | |
ResultsCell = new TableCell(); | |
ResultsCell.ColumnSpan = (MinCells * 2); | |
ResultsCell.Attributes["align"] = "right"; | |
Button btnAddEntrantsScores = new Button(); | |
btnAddEntrantsScores.ID = "btnAddEntrantsScores"; | |
btnAddEntrantsScores.Attributes["width"] = "50px"; | |
btnAddEntrantsScores.Text = "Save"; | |
btnAddEntrantsScores.Click += new EventHandler(this.btnAddEntrantsScores_Click); | |
Button btnCancelEntrantsScores = new Button(); | |
btnCancelEntrantsScores.ID = "btnCancelEntrantsScores"; | |
btnCancelEntrantsScores.Attributes["width"] = "50px"; | |
btnCancelEntrantsScores.Text = "Cancel"; | |
btnCancelEntrantsScores.Click += new EventHandler(this.btnCancelEntrantsScores_Click); | |
ResultsCell.Controls.Add(btnAddEntrantsScores); | |
ResultsCell.Controls.Add(btnCancelEntrantsScores); | |
ResultsRow.Cells.Add(ResultsCell); | |
EntrantsResultsTable.Rows.Add(ResultsRow); | |
} |
<script type="text/javascript"> | |
function SendTab(nextField, strField, evtKeyPress) { | |
alert("hi"); | |
var aKey = evtKeyPress.keyCode ? | |
evtKeyPress.keyCode : evtKeyPress.which ? | |
evtKeyPress.which : evtKeyPress.charCode; | |
if (aKey == 13) { | |
document.getElementById(nextField).focus(); | |
} | |
//Check its text | |
if (aKey == 49 && document.getElementById(strField).value == '') { | |
return; | |
} | |
else { | |
document.getElementById(nextField).focus(); | |
} | |
} | |
</script> |
Any help appreciated, ta.