Call javascript from C#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I can not see mto figure this out. I have a usercontrol using scriptmanager for some update panels. all I am trying to do is add a validator that calls a javascript alert if things are missing. see the code below. it does not throw an error but I can nto see m to get the alert to work. any ideas?<br/>
<pre lang="x-c# protected void BtnCalculate_Click(object sender, EventArgs e)
{
if ((DdlLoanCalcState.SelectedIndex > 0) && ((DdlLoanCalcCounty.SelectedIndex > 0) || (DdlLoanCalcCity.SelectedIndex > 0)))
{
string cityCounty = "";
int countyID;
if (DdlLoanCalcCounty.SelectedIndex > 0)
{

cityCounty = DdlLoanCalcCounty.SelectedItem.Text + " County, ";
countyID = int.Parse(DdlLoanCalcCounty.SelectedValue);

}
else
{

cityCounty = DdlLoanCalcCity.SelectedItem.Text + ", ";
DataSet GetCounty = new DataSet();
GetCounty = LoanLimits.GetCountyByCity(int.Parse(DdlLoanCalcCity.SelectedValue));
countyID = int.Parse(GetCounty.Tables[0].Rows[0]["CountyID"].ToString());

}



DataSet GetLoanLimit = new DataSet();

GetLoanLimit = LoanLimits.GetLoanLimitByCounty(2010, countyID);
int loanLimit = int.Parse(GetLoanLimit.Tables[0].Rows[0]["LoanLimit"].ToString());

string totalDown = Regex.Replace(TxtDownPayment.Text, @"[^d.]*", "");

TxtDownPayment.Text = String.Format("{0:0.##}", totalDown);

string downPayementText = " with a down payment of " + decimal.Parse(TxtDownPayment.Text).ToString("C0");

if (TxtDownPayment.Text == "0")
{
downPayementText = " with no down payment";
}


int totalLoanLimit = ((int.Parse(TxtDownPayment.Text) * 4) + loanLimit);
if (totalLoanLimit < 0) { totalLoanLimit = 0; }

LblTotalLoan.Text = "The maximum VA loan amount for a property in " + cityCounty + DdlLoanCalcState.SelectedItem.Text + downPayementText + " is " + decimal.Parse(totalLoanLimit.ToString()).ToString("C0");

}
else
{

System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert(Your Message);", true);



}



}[/code]

View the full article
 
Back
Top