How disable submit button with javascript

 I seen some code on codeproject.com web site how to avoid inserting twice when user refresh page in ASP.NET. Here is a quick tip how to prevent double submission of the form request while it is processing on the server. I would use html and javascript for this example. First I wound need to add javascript function in the head of the html document.

<sctript>function disablebutton(){

document.getElementById(‘btnsubmit’).disabled=true;

return true;

}

</script>

Then I would need to add onsubmit event in form tag or onclick event on submit button. I will demonstrate onclick event below.

<form auction=”" id=”form1″ name=”form1″><input type=”submit” value=”submit” onclick=”return disablebutton() ;” />

</form>

In addition to javascript function above I can add validation for requered fields in the form. So it is very easy to avoid double post with simple javascript function.

 

 

 

 

Posted in .Net development, php web development | Leave a comment

how to connect mysql database with asp.net application

 

One of my customers has asked me to create application in asp.net which ftp files from host and save them in file directory. I have done application in .Net with C sharp. Couple weeks later, he called me up again and asked to write a program to process these files and store records from files into MySql database within that .Net program. Ops dot net usually goes with MS Sql server. Ok so I found the way to do it.

First I download MySQl connector for .Net from ocacle website. Copy Mysql.data.dll in my bin folder. Set reference to that dll in the project.
Then I added code bellow to class file with following statement

imports MySql.Data;
imports Mysql.Data.MysqlClient;

The rest of code is open database connection

MySqlConnection cn= new MySqlConnection();
cn.ConnectionString= Resources.connectionString;

Then you can use MySql command object or data adapter

Very simple to access and retrieve data from MySql database with  asp.net

Posted in .Net development | Tagged | Leave a comment

How to hide column in gridview asp.net

Just got a call from customer asking me not to display last two columns on the gridview for some condition. The project was done in c sharp. So I have tryied to do it with one line of code by following code but it did not work out.

GridView1.Columns[0].Visible = false;

Then I realised I need to hide header and column for each row iin greadview. So after I bind gridview to data source I hide header column and then with for each loop I hide column in each row of greadview. Look code sample below 4 lines of code do the trick.

GridView1.DataBind();
GridView1.HeaderRow.Cells[0].Visible = false;
foreach (GridViewRow gvr in GridView1.Rows)
{
gvr.Cells[0].Visible = false;
}
Posted in .Net development | Leave a comment

How to merge MS Access with Word using vba

Couple days ago got small vba project to fill Microsoft word document with data from access database. The access database UI form has several sub forms in different tabs on top of the form menu bar with buttons. One of the buttons should open word document with data elements taken from sub forms.
So let’s get started. In order to open word document in vba I would need to set reference to Microsoft word active X library or we can do it using createObject. In my earliest post I demonstrated how to add reference including screenshots use this link to view it http://www.esoftcoder.com/blog/vba-merging-excel-files .

On button click event I am adding the code to open word document template and populate bookmarks. See code below

Const strDir As String = “C:\Crossings\Master Final Report Version 15 Bookmarked.doc”Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject(“Word.Application”)Set objDoc = CreateObject(“Word.Document”)
Dim strMergedDocName As String
objWord.Application.Visible = True
Set objDoc = objWord.Documents.Open(strDir)

With objWord
.Application.Visible = True
If (IsNull([DOTID].[Column](10)) Or [DOTID].[Column](10) = “”) Then
.ActiveDocument.Bookmarks(“GI_E11″).Range.Text = “”
Else
.ActiveDocument.Bookmarks(“GI_E11″).Range.Text = .ActiveDocument.Bookmarks(“sum”).Range.Text = Forms!GeneralInfo.RailTrack.Form.TWT + Forms!GeneralInfo.TrafficSignal.Form.Text35 + 4
End If
Application.Documents(1).SaveAs (“C:\Crossings\Master Final Report Version 15 Bookmarked” & Day(Now) & Month(Now) & Year(Now) & Hour(Now) & Minute(Now) & “.doc”)

End With

Set objWord = Nothing
Set objDoc = Nothing

So above I opened create word object then open template document with bookmark and assign value one of the text box and save document. It is realy easy to use bookmarks to merge MS Access application with word document template.

Posted in MS-Access-Developmen, vba development | Leave a comment

delete all items in dropdown list

In asp.net sometimes dropdown list needs to reload. If an AppendDataBoundItems attribute set to true then each time list get reloaded values will be accumulated So before populating a list script need to erase or remove all the items in the list. Below is an example how to do it in c sharp

int count = dSalesPerson.Items.Count – 1;
for (int i = count; i > 0; i–) dSalesPerson.Items.RemoveAt(i);

Simple easy way to remove items from the dropdownlost.

Posted in .Net development | Leave a comment

Browse files using ftp in vb.net

Couple post before I described how to upload fiels with vb.net now i will show you function to list all directories on remote server with ftp.
Function will accept several parameters like host user name password and directory on the server an return list of string so you can process them as you need it.

In the head of the class please don’t forget to add following statment

Imports System.Net

Below is code of the function.

 

Public Function GetFileList(ByVal host As String, ByVal username As String, ByVal password As String, ByVal currentdirectory As String) As List(Of String)
        Dim oFTP As FtpWebRequest = CType(FtpWebRequest.Create(host & currentdirectory), FtpWebRequest)
        oFTP.Credentials = New NetworkCredential(username, password)
        oFTP.KeepAlive = True
        oFTP.Method = WebRequestMethods.Ftp.ListDirectory
        Dim response As FtpWebResponse = CType(oFTP.GetResponse, FtpWebResponse)
        Dim sr As StreamReader = New StreamReader(response.GetResponseStream)
        Dim str As String = sr.ReadLine
        Dim oList As New List(Of String)
        While str IsNot Nothing
            If str.StartsWith(My.Resources.MerchantID) Then
                oList.Add(str)
            End If
            str = sr.ReadLine
        End While

 

        sr.Close()
        response.Close()
        oFTP = Nothing
        Return oList
    End Function

You see how easy to create function which will bring you back list of all directories and files on remote server.

 

Posted in .Net development | Leave a comment

Watermark textbox with Jquery

Sometimes contact form on the site doesn’t have place for textbox labels and we need to use textboxes instead of labels on the site or top of texbox. So in help we got JQuery plugin watermaek 1.0 you can download form Jquery official web site I will demonstrate how to inplement it. This time insted of add file with plugin in the head do the document I will copy it in the head
so below is the code we will add into head of html php or asp.net docment.

 

  <link href=”Scripts/themes/base/jquery.ui.all.css” rel=”stylesheet” type=”text/css” />
        <script src=”Scripts/jquery-1.4.1.js” type=”text/javascript”></script>
        <script src=”Scripts/jquery.ui.core.js” type=”text/javascript”></script>
        <script src=”Scripts/jquery.ui.widget.js” type=”text/javascript”></script>
        <script src=”Scripts/jquery.ui.tabs.js” type=”text/javascript”></script>
        <script src=”Scripts/jquery.ui.datepicker.js” type=”text/javascript”></script>
        <script type=”text/javascript”>
 �
 �
  var $j = jQuery.noConflict();
function watermark(id, watermarkText, watermarkColor, activeColor) {
 $j(id).val(watermarkText).css(‘color’, watermarkColor).focus( function() {
  if($j(this).val() == watermarkText) {
   $j(this).val(”);
   $j(this).css(‘color’, activeColor);
  }
 }).blur( function() {
  if(!$j(this).val()) {
   $j(this).val(watermarkText).css(‘color’, watermarkColor);
  }
 });
}
$j(document).ready( function() {
watermark(‘input#first_name’, ‘First Name’, ‘#ccc’, ‘#000′);
watermark(‘input#last_name’, ‘Last Name’, ‘#ccc’, ‘#000′);
watermark(‘input#email’, ‘Email’, ‘#ccc’, ‘#000′);
watermark(‘input#phone_number’, ‘Phone’, ‘#ccc’, ‘#000′);
watermark(‘textarea#comments’, ‘Comments’, ‘#ccc’, ‘#000′);

});

 

Now I write html form

<form action=”" method=”post” onsubmit=”return ValForm();”>
          <table>
             <tr><td><div id=”freeconsultation”>FREE CONSULTATION</div></td></tr>
             <tr>
                 <td>
                     <table>
                         <tr>
                             <td><input type=”text” id=”first_name” name=”first_name” style=”width:90px”/></td>
                                <td><input type=”text” id=”last_name” name=”last_name” style=”width:110px” /></td>�
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td><input type=”text” id=”email” name=”email” style=”width:210px” /></td>
                </tr>
                <tr>
                    <td><input type=”text” id=”phone_number” name=”phone_number” style=”width:210px” /></td>
                </tr>
                 <tr>
                    <td><textarea id=”comments” name=”comments” rows=”3″ style=”width:210px” ></textarea></td>
                </tr>
                <tr>
                 <td></td>
                </tr>
                <tr>
                 <td align=”center”><input type=”submit” value=”SUBMIT” style=”width:125px; height:40px; background-color:#FF0000; color:#FFFFFF;” /></td>
                </tr>
            </table>
         �
         �
         </form>

 

Here is and life example of the form http://sisasystems.com 

In this article I demostrate how easy to use watermarks with JQuery.

 

 

Posted in .Net development, JQuery, php web development | Leave a comment

How to create tabs with jquery

Tabs are very popular web2.0 future in web application development. I could not believe how easy to implement tabs with JQuery vs javascript and css. So for start you need to download JQuery css and Javascript files from www.jquery.com.
Then we need to place following libraries into head of html php or asp.net document. In PHP I sagest to add in into header.php and then use include in the rest of pages. For asp.net I would do the same in master page.

<script src=”Scripts/jquery-1.4.1.js” type=”text/javascript”></script><script src=”Scripts/jquery.ui.core.js” type=”text/javascript”></script>

<script src=”Scripts/jquery.ui.widget.js” type=”text/javascript”></script>

<script src=”Scripts/jquery.ui.tabs.js” type=”text/javascript”></script>

Then we need to add small javascript code

<script src=”Scripts/jquery.ui.datepicker.js” type=”text/javascript”></script>

<script type=”text/javascript”>

$(function () {

$(“#tabs”).tabs();

});
</script>

And the last step we need to add html code for hour tabs

<div id=”tabs”>       <ul>

              <li><a href=”#Facilities”>Facilities</a></li>

             <li><a href=”#Tray”>Trays</a></li>

            <li><a href=”#Services”>Services</a></li>

            <li><a href=”#Contacts”>Contacts</a></li>

            <li><a href=”#Disciplines”>Departments</a></li>

       </ul>

       <div id=”Facilities”> some text and html </div>

      <div id=”Tray”> some text and html </div>

      <div id=”Services”> some text and html </div>

      <div id=”Contacts”> some text and html </div>

      <div id=”Disciplines”> some text and html </div> 

<div>

I am using in all my development project where need to use tabs. Jquery is the best approche for tabs.

One more trick to open specific tab you need add one line of code

$(document).ready(function() {$(“#tabs”).tabs({ selected: 1 });

 

 In method tabs argument is selected tab.

 

 

Posted in .Net development, JQuery, php web development | Leave a comment

How to get data form other excel file with vba

Last week I got very small project from one of my clients to create vba micro to process data row by row from one excel file brake one text column into records with 250 characters long and write output into new excel file. First I decided to use ADO (AxtiveX Data object) I wrote a code to open adodb connection and use recordset to process records in the file. But somehow data got corrupted in some of the records. I could not figure out why.
So I started thinking about alternative solution and come up with brilliant idea. I decided to use workbook object.
I created workbook and worksheet objects for each of the files.

Dim wb As Workbook
Dim wb2 As Workbook
Dim ws As Worksheet
Dim ws1 As Worksheet

Next I promt client enter file location in data folder

Dim a As String
a = InputBox(“Please enter file name you want to process” & vbNewLine & “make sure file is located in c:/data/ folder”)

If Len(a) = 0 Then
MsgBox “Please start again and enter file name”
Exit Sub
End If

Then I opened both files.

Set wb = Workbooks.Open(“c:\data\” & a, True, True)
Set wb2 = Workbooks.Open(“c:\data\notes2.xlsx”, True, False)
Set ws = wb.Worksheets(1)
Set ws1 = wb2.Worksheets(1)

After that I determinate last row in input file

Dim lastrow As Long
lastrow = ws.Cells.Find(“*”, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

And now I looped thruout the records and chanked text column into multiple records

Dim l As Integer
Dim i As Integer
Dim y As Long
Dim r As Long
Dim dr As Integer

r = 1
y = 1

Do Until r > lastrow

If IsNull(ws.Cells(r, “g”).Value) Or ws.Cells(r, “g”).Value = Empty Then
l = 0
Else
l = Len(ws.Cells(r, “g”).Value)
End If
i = 1
dr = 1
If l = 0 Then
ws1.Cells(y, “a”).Value = ws.Cells(r, “a”).Value
ws1.Cells(y, “b”).Value = 1
ws1.Cells(y, “c”).Value = dr
ws1.Cells(y, “d”).Value = ws.Cells(r, “d”).Value
ws1.Cells(y, “e”).Value = ws.Cells(r, “e”).Value
ws1.Cells(y, “f”).Value = ws.Cells(r, “f”).Value
ws1.Cells(y, “g”).Value = “”
y = y + 1
Else
Do Until l < 1
ws1.Cells(y, “a”).Value = ws.Cells(r, “a”).Value
ws1.Cells(y, “b”).Value = 1
ws1.Cells(y, “c”).Value = dr
ws1.Cells(y, “d”).Value = ws.Cells(r, “d”).Value
ws1.Cells(y, “e”).Value = ws.Cells(r, “e”).Value
ws1.Cells(y, “f”).Value = ws.Cells(r, “f”).Value
If l < 250 Then
ws1.Cells(y, “g”).Value = Mid(ws.Cells(r, “g”).Value, i)
Else
ws1.Cells(y, “g”).Value = Mid(ws.Cells(r, “g”).Value, i, 250)
End If

l = l – 250
i = i + 250
dr = dr + 1
y = y + 1

Loop
End If
r = r + 1
DoEvents
Loop

Adn finally I closed all the objects, released memory and display message that process completed.

wb.Close False
wb2.Close True
MsgBox “Process Completed”
Set ws1 = Nothing
Set ws = Nothing
Set wb = Nothing

In my openion this is the easiest way to process data from one input file and produce output file. if anyone know others ways to do it please post. I would love to hear from you

Posted in MS-Access-Developmen, vba development | Leave a comment

email function for asp.net

Email function is most useful function in today web development most of the sites have contact form request forms and etc .. In this post I will post email function which will accept 1 or more email address subject and html body of the email

In order to send email in asp.net application we need to modify web.con fig file adding smtp server properties or mail settings. Below is a code from web.config file. I use default credentials but you may need to change it according security settings on hosting provider you are using.







This time I use VB.NET to create email function. I am planning to post C sharp soon.

Public Sub SendEmail(ByVal emailAddress As String, ByVal Subject As String, ByVal Body As String)
Dim message As New MailMessage

Dim mf As New MailAddress(“someemailaddress@doomain.com”)
Dim emailClient As New SmtpClient
Dim a() As String = emailAddress.Split(“;”)

Dim i As Integer
Try
For i = 0 To a.Length – 1
If String.IsNullOrEmpty(a(i).ToString) = False Then
message.To.Add(a(i))
End If
Next

message.From = mf
message.IsBodyHtml = True
message.Subject = Subject
message.Body = Body
emailClient.UseDefaultCredentials = True
emailClient.Send(message)
Catch e As Exception
Finally
End Try

End Sub

So you can see this function very easy to use just pass string of emails delimeted by “;” subject and body of email and you are done.

Posted in .Net development | Leave a comment