Consuming CurrencyConverter web service through JavaScript


Hi,

For getting the currency conversion rate we could use the following web service provided by Generic Objects Technologies Ltd.

Check out the web services provided by them

http://www.webservicex.net/WCF/webServices.aspx

To consume their currency converter web service

http://www.webservicex.net/CurrencyConvertor.asmx we could use the following JavaScript code

var xmlHttp;
function SoapCall() {
// creatng the xmlHttp object
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
// Calling the web service using post and true means asynchronous call
xmlHttp.open(“post”, “http://www.webservicex.net/CurrencyConvertor.asmx”, false);
// Setting the request header to let the web service identify the soap request we would be sending

xmlHttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

xmlHttp.setRequestHeader(“SOAPAction”, “http://www.webserviceX.NET/ConversionRate”);

var soapRequest = “<?xml version=’1.0′ encoding=’utf-8′?> ” +
“<soap12:Envelope xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance&#8217; xmlns:xsd=’http://www.w3.org/2001/XMLSchema&#8217; xmlns:soap12=’http://www.w3.org/2003/05/soap-envelope’>&#8221; +
” <soap12:Body>” +
”   <ConversionRate xmlns=’http://www.webserviceX.NET/’>&#8221; +
”     <FromCurrency>USD</FromCurrency>” +
”    <ToCurrency>INR</ToCurrency>” +
”  </ConversionRate>” +
“</soap12:Body>” +
“</soap12:Envelope>”;

xmlHttp.send(soapRequest);
alert(xmlHttp.responseText);

}


Bye..

Reading querystring using javascript


Hi while searching for the same,

got the following javascript

q = location.search;

getParam = function(arg) {
if (q.indexOf(arg) >= 0) {
var pntr = q.indexOf(arg) + arg.length + 1;
if (q.indexOf(‘&amp;’, pntr) >= 0) {
return q.substring(pntr, q.indexOf(‘&amp;’, pntr));
} else {
return q.substring(pntr, q.length);
}
} else {
return null;
}
}

var objectId = getParam(‘oId’);

alert(objectId);

or better

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split(“&”);
for (i=0;i<gy.length;i++) {
ft = gy[i].split(“=”);
if (ft[0] == ji) {
return ft[1];
}
}
}

var pId= querySt(“pId”);
alert(pId);

http://ilovethecode.com/Javascript/Javascript-Tutorials-How_To-Easy/Get_Query_String_Using_Javascript.shtml

Here oId is the query string parameter whose value we need.

This works even if there are multiple query string parameters !

Bye…

Error : The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.


Hi,

I got this error while developing an asp.net page with Sql server as database,

On checking the sql query i found out that the date value was not being sent in the format expected by the database , so by changing the format within my query resolved the issue !

Initially it was calendar.ToShortDateString() and i changed it to 

Calendar1.SelectedDate.ToString(“MM/dd/yyyy”)

Bye…

Error : This application is already precompiled in ASP.NET


Hi,

I was getting this error while trying to build one of the web site in Visual studio, on some searching found out the error was because of an existing PrecompiledApp.config within the application folder!

On deleting that file and rebuilding the web site, everything was back on track !

Bye..

Gridview SelectedIndexChanged Showing no Data


It could happen if we are dynamically creating DataTable and bounding it to our GridView. Searching for it if found the following information on one of the blog

 

The GridView (and actually, all our data controls) does not save data items across postbacks.  This reduces ViewState (if the objects are even serializable) and enables garbage collection to happen and clean up your objects.  So, when you click the button to post back, the GridView has not called DataBind and therefore your data item isn’t there.  This is what you’ve discovered.

Selection is handled slightly differently than choosing an edit item, sorting, paging, or other functions: because those other functions require a change in the control tree or a query to the data source to get different data, they cause a DataBind to happen automatically at some point before the control renders again.  You can handle RowDataBound and get your data item.  Selection, however, doesn’t require new data or a different control tree (all that usually changes is the style properties on the row), so it will never call DataBind.  This makes selection very fast.  It also means you won’t get a DataBound or RowDataBound event unless you call DataBind yourself.  So you can’t use that event to get your data item unless you call it yourself.  If you need the data item, you can call DataBind yourself directly to get it, then handle OnRowDataBound, check the row index against the SelectedIndex, and get the data item.

However, this is kind of the shotgun method- it will get you what you want, but the performance has decreased because you’ve called DataBind again.  Also, if the data in the data store has been modified between your calls to databind, the row index that was the selected item may now point to a different row or just different data.  What data are you really looking for from the selected data item?  Is it just one or two fields?  If so, consider using DataKeyNames to store these fields, and then you can get to them via the DataKeys property.  If you don’t want to suffer the hit to ViewState from DataKeyNames, consider getting the data directly from the controls in the row of the GridView.

So I followed the suggestion highlighted in yellow and was able to retrieve the value for the selected row.

 

  protected void grdPropertyValues_SelectedIndexChanged(object sender, EventArgs e)

    {       

        GridViewRow row = grdPropertyValues.SelectedRow;

        // Get the selected row index

        iRownum = grdPropertyValues.SelectedIndex;

        // call the method that dynamically creates the DataTable and

        // bind the gridview to it

        BindConferenceDayToGrid(myList, grdPropertyValues);

    }

 

 

protected void grdPropertyValues_RowDataBound1(object sender, GridViewRowEventArgs e)

    {

        // getting the GridViewRow

        GridViewRow row = e.Row;

        // if RowType is DataRow and RowIndex is our selected row’s index

        if (e.Row.RowType == DataControlRowType.DataRow && row.RowIndex == iRownum)

        {       

                DataRowView drv = (DataRowView)e.Row.DataItem;

                Response.Write(“The value we need “+drv.Row[1].ToString());          

        }      

    }

 

That’s it ..

 

 

 

%d bloggers like this: