Reputation: 758
I'm sorry for that question but somehow I have a blackout (I know its not a excuse ) but how can I retrieve the value from a RadNumbericTextBox
using a button to sent the value (I need a int)
<div class="fromRowDiv">
<asp:Label ID="label1" CssClass="fromLabel" runat="server" Text="From Date" ></asp:Label>
<telerik:RadNumericTextBox ID="fromYear" runat="server" MinValue="2000" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="" ></telerik:RadNumericTextBox>
<asp:Label ID="Tolabel2" CssClass="fromLabel" runat="server" Text="To Date"></asp:Label>
<telerik:RadNumericTextBox ID="toYear" runat="server" MinValue="2000" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator=""></telerik:RadNumericTextBox>
</div>
protected void CalcButton_Click(object sender, EventArgs e)
{
AnnualVacationManager mng = new AnnualVacationManager();
mng.CalcForNextYear(fromYear,toYear);
}
I need the value from RadNumbericTextBox (dynamic )
public AnnualVacationManager() {
}
public void CalcForNextYear(int fromYear, int toYear)
{
IEnumerable<HtUser> allUsers = HtUser.GetAll();
List<AnnualVacation> newAnnualVacations = new List<AnnualVacation>();
if (allUsers.Any()) {
foreach (HtUser user in allUsers) {
//int fromYear = 2013;
//int toYear = 2014;
IEnumerable<AnnualVacation> usersCurrentAnnualVacation = new List<AnnualVacation>(user.AnnualVacations.Where(a =>a.FromDate.Value.Year >= fromYear && a.FromDate.Value.Year < toYear));
if (usersCurrentAnnualVacation.Any()) {
foreach (AnnualVacation existing in usersCurrentAnnualVacation) {
AnnualVacation newAnnualVacation = new AnnualVacation();
//Year stuff
DateTime newFromDate = existing.FromDate.Value;
newFromDate.AddYears(toYear - fromYear);
DateTime newToDate = existing.ToDate.Value;
newToDate.AddYears(toYear - fromYear);
//
newAnnualVacation.FromDate = newFromDate;
newAnnualVacation.ToDate = newToDate;
newAnnualVacation.WorkingTime = existing.WorkingTime;
newAnnualVacation.VacationDays = existing.VacationDays + (existing.VacationDays - user.GetBookedVacation(fromYear));
newAnnualVacations.Add(newAnnualVacation);
newAnnualVacation.HtUser = user;
}
}
}
HtEntityFactory.Context.SaveChanges();
}
}
}
}
Upvotes: 1
Views: 6465
Reputation: 50728
The RadNumericTextBox has a Value property on the server-side that returns a nullable decimal (or maybe double) with the numeric value the user entered. To get the value, provided it has been supplied a valid value, you do:
//First .Value returns the nullable decimal or double
//second .Value gets the decimal or double in non-nullable form
fromYear.Value.Value
On the client, it should have a get_value()
method to get it as in:
var box = $find("<%= fromYear.ClientID %>");
var val = box.get_value();
You may need to format the number in a specific format, so see this for specifics to how you can tailor the input of numbers, specifically:
<NumberFormat DecimalDigits="0" />
Supply the values to the method as:
mng.CalcForNextYear(Convert.ToInt32(fromYear.Value.Value),
Convert.ToInt32(toYear.Value.Value));
And that should solve the problem. You HAVE to have a value in the RadNumericTextBox controls for this to work. Otherwise, check for null first.
Upvotes: 2
Reputation: 23
int fromyearvalue = convert.toint32(fromYear.text)
int toyearvalue = convert.toint32(toYear.text)
mng.CalcForNextYear(fromyearvalue ,toyearvalue );
OR
mng.CalcForNextYear(= convert.toint32(fromYear.totext)),convert.toint32(toYear.totext));
Upvotes: 0