Rss Feed Like Us on facebook Google Plus
Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

November 18, 2013

Retrieve Data from Client Machine DataBase on Web using Javascript Active-X object

To Retrieve data from Local database you can use JavaScript simulation using Active-X
object on your Asp.net Website.

If all of your users are on Windows computers, you could use ADO or ODBC to connect to a corresponding database. checkout the example

Limitations:
This script will work only on Internet Explorer

EXAMPLE

SCRIPT:

<script id="clientEventHandlersJS" type="text/javascript">
        function GetData() {
            var connection = new ActiveXObject("ADODB.Connection");
            var connectionstring = "Data Source=AJIT-LAPTOP\\sqlexpress;Initial Catalog=user;User ID=ajit;Password=ajit;Provider=SQLOLEDB";
            connection.Open(connectionstring);
            if (connection) {
                var rs = new ActiveXObject("ADODB.Recordset");
    //FOR Single Record
                var userid = document.getElementById("txtuserid").value;
                rs.open("select password from userdetail where userid='" + userid + "'", connection);
                if (!rs.EOF) {
                    var c1 = rs.fields("userid").value;
                    alert(c1);
                }
                else {
                    alert("Record Not Found");
                }
              //For Multiple Records
          rs.Open ("select col1,col2 from tbl_test", conn,0,1);
          while (! rs.EOF)
          {
             c1 = rs.fields("col1").value;
             c2 = rs.fields("col2").value;
             document.write(c1+' - '+c2+'<br>');
             rs.MoveNext ();
          }
                rs.close();
                rs = null;
                connection.close;
                return true;
            }
            else {
                return false;
            }
        }
    </script>

HTML:

<form id="form1" runat="server">
    <table>
        <tr>
            <td>
               USER ID: <input type="text" id="txtuserid" runat="server" />
                <input type="button" id="btn" onclick="javascript:return GetData()" style="width: 80px;
                    height: 30px;" value="OK" runat="server" />
            </td>
        </tr>
    </table>
    </form>



Read More

November 17, 2013

AngularJS open-source JavaScript framework, maintained by Google

Its provide browser-based applications with MVC capability, in an effort to make easier development and testing.The library reads in HTML that contains additional custom tag attributes; it then obeys the directives in those custom attributes, and binds input or output parts of the page to a model represented by standard JavaScript variables. The values of those JavaScript variables can be manually set, or retrieved from static or dynamic JSON resources.

 

Angular JS Script:

<head>
 <script src="http://code.angularjs.org/1.2.1/angular.min.js"></script>
</head>

Angular directives:AngularJS directives allow developer to specify custom and reusable HTML tags that moderate the behavior of certain elements.

1: ng-app 
Declares angularJS as a root element of the application allowing behavior to be modified through custom HTML tags.
<html ng-app>
...........
</html>

2: ng-bind
Automatically changes the text of a HTML element to the value of a given expression.
<div ng-controller="Ctrl"> 
 Enter name: <input type="text" ng-model="name"><br> 
 Hello <span ng-bind="name"></span>
</div>

3: ng-model
Similar to ng-bind, but allows two-way data binding between the view and the scope.
 <input type="text" ng-model="name">


4: ng-class 
Allows class attributes to be dynamically loaded.  
<span class="base-class" ng-class="..">

5: ng-controller 
Specifies a JavaScript controller class that evaluates HTML expressions. 
<body ng-controller="...">

6: ng-repeat
Instantiate an element once per item from a collection. 

7: ng-show & ng-hide
Conditionally show or hide an element, depending on the value of a boolean expression. 
<div class="check-element animate-show" ng-show="checked">

8: ng-switch
Conditionally instantiate one template from a set of choices, depending on the value of a selection expression.  

9: ng-view
The base directive responsible for handling routes that resolve JSON before rendering templates driven by specified controllers. 

10: ng-if 
Basic if statement directive which allow to show the following element if the conditions are true.

Example:
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>

Learn More...
Read More

August 29, 2013

JQuery ColorBox : Do Postback for inline HTML

While using JQuery Color Box with inline content , postback of submit button is not working...



CAUSE:
Color Box script generates an iframe for your target Page/Html.In case of inline content/html ColorBox generates an iframe outside the  <form> tag. As we all know to do postback we need  <form> tag. So in generated iframe HTML there is no  <form> tag available.

SOLUTION:
very simple hack , we have to just append the generated iframe html to <form> tag. checkout the below script.

SCRIPT

<script type="text/javascript">
        function cbox() {
            $.colorbox({ inline: true, width: "50%", href: "#inline_content", onOpen: AllowPostback });
        }
        function AllowPostback() {
            $("div#cboxOverlay").appendTo("form:first");
            $("div#colorbox").appendTo("form:first");
        }
    </script>

HTML

<div id='inline_content' style='padding:10px; background:#fff;'>
      <h2>Inline Content </h2>
      <input type="submit" id="btn" name="btn" />
</div>



Read More

August 9, 2013

Disable Ctrl+C ,Ctrl+V ,Ctrl+A in a web page : Javascript

Question How to disable Ctrl+C , Ctrl+V , Ctrl+A in any web page by using javascript.

More..
Disable Button after clicking on it.

Solution:
just copy and paste below script in <head> section


<script type="text/javascript">
        function Disable_Control_C() {
            var keystroke = String.fromCharCode(event.keyCode).toLowerCase();
 
            if (event.ctrlKey && (keystroke == 'c' || keystroke == 'v' || keystroke == 'a')) {
                alert("This function not allowed");
                event.returnValue = false; // disable Ctrl+C
            }
        }
    </script>

and call the function in html body

<body onkeydown="javascript:Disable_Control_C()">
Hello World!
</body>
</html>
Read More

August 7, 2013

Disable Right Click Button - Javascript

while developing web application ,some situation arises where we have to disable right click button of a mouse in web pages of Asp.Net,PHP ,JSP. you can achieve this by using Javascript.

Qusetion - How to disable right click button of mouse in webpage.

Solution- 
add below script in head section of web page

<script type="text/javascript">
        var msg = "This function is disabled!";
        var bV = parseInt(navigator.appVersion)
        var bNS = navigator.appName == "Netscape"
        var bIE = navigator.appName == "Microsoft Internet Explorer"
 
        function nrc(e) {
            if (bNS && e.which > 1) {
                alert(msg)
                return false
            } else if (bIE && (event.button > 1)) {
                alert(msg)
                return false;
            }
        }
 
        document.onmousedown = nrc;
        if (document.layers) window.captureEvents(Event.MOUSEDOWN);
        if (bNS && bV < 5) window.onmousedown = nrc;
    </script>
..........................................................................................

Read Also...

How to prevent page going back on backspace button click

Read More

July 4, 2013

How to prevent page going back on backspace button click

Stop page going back on backspace button click in asp.net,C#,java,PHP.


1. To prevent page going back on backspace or browser back button. you can achieve this by short snippet by javascript below.

<script type="text/javascript">
function preventBack() 
{ 
    window.history.forward(); 
}
setTimeout(function () { preventBack() }, 0);
window.onunload = function () { null };
</script>
.

Follow my blog with Bloglovin
Read More

Disable Button after once Click by Javascript

Disable Button after clicking on it.If when you set disabled="disabled" immediately after
the user clicks the button, and the form doesn't submit because before form submission button is already diasabled..

Uses- It prevents double form submission/ prevent double postback


 you could try these things

1st Way...

//JAVASCRIPT
<script type="text/javascript">
function disable() {
            var v = confirm('Are you sure to save');
            if (v == true) {
                setTimeout(function () { document.getElementById('<%= btnSave.ClientID %>').disabled = true }, 1);
                return true;
            }
            return false;
        }
 
        function preventBack() { window.history.forward(); }
        setTimeout(function () { preventBack() }, 0);
        window.onunload = function () { null };
</script>
//HTML
<input type="button" id="btnsave" runat="server" value="Save" onclick="javascript:disable()" />
2nd Way

myInputButton.disabled = "disabled";
myForm.submit()
Whether it be due to a users lack of tech know-how or a twitch of the finger, a secondary click of a forms ‘Submit’ button could result in the form being submitted twice. Depending on the action of the form this could in turn send two enquiries, create two orders or insert a record into the database twice.

3rd Way

<input type="submit" name="Submit" value="Submit" onclick="this.disabled=true; this.value='Please Wait...';" /> 

4th Way
We can also use AJAX to disable postback element on Request Begin to prevent multiple clicks.

<form id="form1" runat="server">
<asp:scriptmanager id="sc" runat="server" enablepartialrendering="true">  
</asp:scriptmanager>
<script type="text/javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginReq);
    function beginReq(sender, args) {
        document.getElementById('<%= lblMessage.ClientID %>').innerText = "Processing.....";
        args.get_postBackElement().disabled = true;
    }  
</script>
<asp:updatepanel id="updpnlSubmit" runat="server">  
    <ContentTemplate>  
        <asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />  
        <asp:Label ID="lblMessage" runat="server"></asp:Label>  
    </ContentTemplate>  
</asp:updatepanel>
</form>

Read More

© 2011-2016 Techimpulsion All Rights Reserved.


The content is copyrighted to Tech Impulsion and may not be reproduced on other websites.