Archive

Archive for July, 2013

Ajax call before form submit asp.net c#

July 28, 2013 4 comments

Let me share an issue i faced.

I have a textbox with google auto complete plugin.

Image

I need to store the place i typed in, its latitude, longitude in to the database.

So google have the javascript api to get the latitude and longitude, but it should be called before the form button click to store that in Hidden fields(my way), so i can get the values in server side(c#).

I tried the OnClientClick, but the hidden fields are not set with lat and long. The form is always submitting before the result is came from the ajax call :(.

I found a solution.

var geocoder;
function SetLatLng() {
geocoder = new google.maps.Geocoder();
           var address1 = document.getElementById("location1").value;
geocoder.geocode({ 'address': address1 }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
$('#HFLat').val(results[0].geometry.location.lat());
$('#HFLng').val(results[0].geometry.location.lng());
$('#SecondButton').click();
}
});
return false;
}
<asp:Button ID="FirstButton" OnClientClick="SetLatLng(); return false;" runat="server" Text="Click" />
<asp:Button ID="SecondButton" OnClick="buttonSubmit_Click" runat="server" Text="Click" style="display:none" />
<asp:HiddenField ID="HFLat" runat="server" Value="" />
<asp:HiddenField ID="HFLng" runat="server" Value="" />

Make 2 buttons, one for running the javascript, if the value is returned from the ajax call, click the second button programmatically 😛

Happy coding 🙂

How to set up virtual port windows 7 c#

July 25, 2013 Leave a comment

Its really cool to have an emulator to set up virtual port in windows 7/XP

A null modem emulator, get it from here

http://sourceforge.net/projects/com0com/

You need to make paired ports to test the data send/receive

Follow the steps below to set up and test the virtual port.

1. Install the null modem emulator (com0com) as Administrator

2. Run the Windows 7 command prompt as administrator

3. Type the following command and hit enter

bcdedit.exe -set TESTSIGNING ON

4. Reboot the computer

5. Open the program com0com setup to configure virtual ports

com0com

6. Create paired ports, So we can test the data transfer. If any data we push to COMA, we can get it at COMB

7. Useful program to test the data transfer between ports is hyperterminal. Unfortunately its not in the Windows 7, its in XP i guess.

You can get the hyperterminal here http://sdrv.ms/15NJAMo

8. You can test the data from the hyperterminal as below

hyper

If you type something in COM A, you can see the text in COM B and vice versa.

Also you can manage the virtual ports from your c# code with SerialPort tool as well.

Happy coding…:):)

Awesome plugin for multiple file upload ajax asp.net

July 2, 2013 Leave a comment

Got a simple and nice plugin for uploading multiple files.

Image

Here is my source code http://sdrv.ms/121hk6G

You can see detailed options here : http://www.albanx.com/ajaxuploader/examples.php?e=2

Happy coding 🙂