Sunday, November 22, 2009

To Disable Button on Submit Using JavaScript

Simple Javascript Snippet to disable button on submitting to server,
this script has to be placed in the page where the button has to be disabled.
Paste the script below the script manager
This function used to disable the button when the server side button is
clicked and after all other validations.

<script language="javascript" type="text/javascript">
//Set function to execute when the event occurs

..Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
//The function which will disable the button

function BeginRequestHandler(sender, args)
{
document.getElementById("$lt%=btnSave.ClientId %>").disabled=true;
//Insert here the script that needs to be executed
//before the request is sended to the server
}

</script>


Add This in WebConfig File

<httphandlers>

<add validate="false" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" path="ScriptResource.axd" verb="GET,HEAD">
</httphandlers>
<httpmodules>
<add type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="ScriptModule">
</httpmodules>

Tuesday, November 3, 2009

To Read Line By Line of Text File in VB.net 2.0

In this Post I have shown the simple code snippet for reading a text file line by line.

Dim strFileName As String = String.Empty
Dim fs As FileStream = Nothing
Dim m_streamReader As StreamReader = Nothing
Dim strCompany As String = String.Empty

fs = New FileStream(strFilePath, FileMode.Open, FileAccess.Read)
m_streamReader = New StreamReader(fs)
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin)

Do
strContent = m_streamReader.ReadLine()

Loop While (Not m_streamReader.EndOfStream)