Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Javascript asynchronous call help

Avatar of claracruz
claracruz asked on
ASP.NET
9 Comments1 Solution948 ViewsLast Modified:
Hello  Experts,

I am using the following  site as a guide to implementing Ajax in my website;- http://www.ajaxpro.info/quickguide.aspx

I have done the following;-

On my usercontrol page I have the following javascript;-

<script type="text/javascript">
function calculateCurrency()
{
   Controls_CurrencyConverter.CalculateCurrency(calculateCurrency_callback); // asynchronous call
}
  //CalculateCurrency(calculateCurrency_callback);  

// This method will be called after the method has been executed
// and the result has been sent to the client.

function calculateCurrency_callback(res)
{
  theForm.lblResult2.value = res.value;
}
</script>

there is by label control and my image button;-
<input type="text" id="lblResult2" maxlength="5px" readonly="readonly" style="width:70px;" />
<img id="btnSubmit" alt="Submit" src="../images/button_convert.gif" onclick="calculateCurrency();"/>  

and in the codebehind of my user control I have the following;-

[AjaxPro.AjaxMethod]
    public string CalculateCurrency()
    {
        try
        {
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("../Rates.xml"));
            DataRow[] rows = ds.Tables[0].Select("Currency = '" + ddlConverter.SelectedItem.Text + "'");

            decimal CurrencyAmount = Convert.ToDecimal(txtCurAmount.Text);
            decimal rate = Convert.ToDecimal(rows[0]["Exchange"]);
            decimal amount = CurrencyAmount * rate;
            return amount.ToString("f2");
           
        }
        catch (FormatException)
        {
            return "Error";
        }
    }

However, when I click submit "null" is returned rather than the correct value. what am I doing wrong?


PS: It works fine if  I replace the HTML image button with an asp.net control and call it normally with the "protected void ImageButton1_Click(object sender, ImageClickEventArgs e)"
ASKER CERTIFIED SOLUTION
Avatar of orbulat
orbulatFlag of Hong Kong image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answers