Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

Thursday, December 25, 2014

How easy to reduce efforts in retesting a asp.net web application?

 

Most of the time when you write code for a web application you need to test it again and again. You have to run a whole flow of positive or negative test cases to check whether your application is working or not.

Now suppose your application have 20 pages and you need to traverse each individual page and may be perform some operation and on each change of your development you need to perform same thing.

sometimes, this thing will irritate you and you will skip testing which may be harmful because most of the time it happens when you skipped something Smile you took a deep breath  and at that moment your application crashed Sad smile.

So , as a responsible developer we do not have to skip any test scenario but next question is how to reduce this effort which you feel boring sometime.

I can say we can reduce this effort by a installing a simple  Firefox add-in which is absolutely free. The add in “Selenium add in”

you can download it from https://addons.mozilla.org/en-US/firefox/addon/selenium-expert-selenium-ide/

once you have installed this you will find the selenium icon near by search bar as shown below

selenium_icon

when you click this icon you will get a selenium interface as shown below

selenium_interface

The basic concept of this tool is what ever you will run in browser it has capability of recording those steps so it is just play button and pause button game, no rocket science. You can easily run and use this.

I am sure it will reduce your testing effort and when when selenium ide will play your test cases you can take a deep breath and enjoy your coffee and snacks.

I hope this tip may be helpful to you somewhere.

Happy Holidays.

Regards,

RJ

Monday, March 31, 2014

Build 2014–2nd–4th April

Dear all,

Its back enjoy build on 2nd & 4th April. Although I am very interested to join and see this great event live at San Francisco but unfortunately Sad smile not able to go there.

I will enjoy video

You can find more detail with below link

http://www.buildwindows.com/

So enjoy learning

Regards,

Rajat Jaiswal

Sunday, March 23, 2014

Sammy.Js–simplest steps to create Restful web application (Single Page Applications) SPAs

Dear All,

Today I  am sharing with you one of the best and easy to understand JS which is “Sammy.Js”.

“Sammy.js” is 16 k java script over JQUERY which provide facility to developer to create RESTFUL SPAs (single Page Application).

It is very  clean, simple and easy to adapt java script.rl

You get Restful URL easily with this.

It added “#”  hash in URL. For example see below example

http://Indiandotnet.com/index#/

http://indiandotnet.com/index#/Products/

http://indiandotnet.com/Index#/products/1

Let us understand this with example.

In last post you have seen how to consume web API with JQUERY http://indiandotnet.wordpress.com/2014/03/21/how-to-consume-web-api-using-jquery/

Here I am using the sample source code to move forward with sammy.js.

What we are planning here to create a page with menus and in this page we will call sammy.js on menu to call responsive URL to show states list ,particular state according to id and default page . as shown in below figure

Html_Sammy_Js

Step 1:-  Add “Sammy.js” in the project using Nuget package manager as shown in below figure

sammyJs_Nuget_Package

Step 2:- Once the Sammy.Js added in your project you will find the Js in your project’s script folder

sammyJs_in_project

Step 3:-

Add sammy js reference in the project

   1: <script src="~/Scripts/jquery-2.1.0.min.js"></script>
   2:    <script src="~/Scripts/sammy-0.7.4.min.js"></script>

Step 4:-


Now below screen shot show the html which is designed to achieve our task


Default_Html


Step 5:- Now when Home menu link click by end user we will show  default page which in Index page in our case and its URL will be


http://localhost:43597/Home/index#/ 


And when user click on States link in navigation then it will show URL


http://localhost:43597/Home/index#/States 


And page will show list of states


last but not the least when user click on MP menu in navigation  then it will show URL


http://localhost:43597/Home/index#/States/1 


and page will show state name according to Id which is currently 1 in above url


Step 6:-


Now to achieve this we need to invoke Sammy.js  as shown below in below code



   1: <script type="text/javascript">
   2:  
   3:       $(document).ready(function () {
   4:           var sammySPA = $.sammy("#main", function () { // initializing main div which is base for SPAs application content 
   5:  
   6:               //Default url  
   7:               this.get('#/', function (context) {
   8:                   
   9:                   context.app.swap(''); // clear what ever previously written in main div
  10:                   $("#main").append("<B> Showing default url content by code</b>"); // this code append the content in msin div 
  11:  
  12:               });
  13:               //below code will fire when user click on state link 
  14:               this.get('#/States', function (context) {
  15:                 
  16:                   //calling the Web API to provide State name array 
  17:                   $.get("http://localhost:43597/api/mystate/", function (data, textStatus) {
  18:                       var str = "";
  19:                       // create list with sate name which again referencing to new url
  20:                       for (var i = 0; i < data.length; i++) {
  21:                           str = str + "<li><a href='#/States/" + (i+1).toString() + "'>" + data[i] + "</a></li>";
  22:                       }
  23:  
  24:                       //Clean the main div 
  25:                       context.app.swap('');
  26:                       //Apeend the data in main div
  27:                       $("#main").append("<ul>" + str + "</ul>");
  28:  
  29:                           
  30:                   });
  31:  
  32:               });
  33:  
  34:               //States/stateId url 
  35:               this.get('#/States/:id', function (context) {
  36:                   //calling web api to get particular state by id
  37:                   $.get("http://localhost:43597/api/mystate/"+ context.params.id, function (data, textStatus) {
  38:                     
  39:                       context.app.swap('');
  40:                       $("#main").append("<h1>" + data + "</h1>");
  41:  
  42:  
  43:                   });
  44:               });
  45:  
  46:         
  47:  
  48:           });
  49:           
  50:           sammySPA.run('#/'); //run sammy.js
  51:  
  52:  
  53:  
  54:       });
  55:   </script>

Step 7:-


Let me explain the above code here


We have define $.sammy function which is bounded with the div whose.


$.sammy(‘#main’,function() {}).run(); this is the basic function to invoke sammy.js


Step 8:- Now to which url we need to entertain by which method like  get, put, Post, delete. We need to define our functionality according to our need in current example we have used get function.


this.get(‘#/’,function (context){});


The meaning of above line is when ever a request (default) invoke by end user just execute function as defined. in the function there is context parameter . Which help in accessing method type (get/post) , parameters


Step 9:-  Now when you run and click on States link you will get following screen


stateResult_sammy


Step 10:- you can test it further I have added list of states also with dynamic url  so when you click on MP, RJ, MH etc in above list you will get a new URL according to our need


statewithparticularId


I hope this example will help you to create your own SPA application.


I defiantly say here “Sammy.js” rock. I like this script hope you will also.


Enjoy learning


your Host


Rajat

Friday, March 21, 2014

How to consume Web API using JQUERY ?

 

Friends,

In last two articles we understood

 what is Web API ? (http://indiandotnet.wordpress.com/2014/02/23/what-is-web-api/)

and How to create it ? (http://indiandotnet.wordpress.com/2014/02/27/how-to-create-web-api/)

Now next is how to consume it ?

So here we will understand this by an example. I am pretty much sure you all  are comfortable with server side code so here in current example we using  client side code to consume web API.

In current example I have created a Web API with name “MyState” . The basic functionality of this Web API is to provide list of all the State with default get method and provide specific state according to provided id.

Let me show you snap shots of created code & running API here

Mystate_Code

Above figure shows default get method which response array of string (name of state)

defaultStateResult

Now to consume this Web API in our project we have added a view with following Java script

in below screen we have used a “get” JQUERY function and as we  know the API URL we wrote that and once the response from API returned we concatenated the response array with <li> tag and show as a innerHTML of stateName div as shown in below fig

consuming_web_Api_JQUERY

Now when we run this program on index.cshtml we got following response

stateResult

In current example we have used  “GET” method we can also consume post operation for INSERT/UPDATE/Delete

I hope you will like this post.

Thanks

Your host

Rajat

Sunday, June 07, 2009

How to add AJAX tab control at run time?

Hello friends,
Today we will discuss how to add Ajax tab control at run time.

As you know for adding tab control in our page we require two Ajax controls one is AJAX Tab Container and second is AJAX tab Panel control.
AJAX tab container is main control and Tab Panel is child control. Now you have to follow step as follow.

Step 1:-
For this first just drag drop a Tab Container on our aspx page.

Step 2 :- Now you have to add panel in tab container for that we have to work in special method of tab Container which is tab Initialize method.
It means you have to work in below event.
Private Sub tabCont_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles tabCont.Init
Try
Me.pvt_DefineTabControl()
Catch ex As Exception
Throw ex
End Try
End Sub
Here I have created a Define tab control method in which we define tab control at run time.
According to my knowledge if you do not use this tab initialize method than you can not use run time control creation. So this event is must when you creating run time tab control

Step3 :- you are thinking what is pvt_DefineTabControl method so it’s a simple work as you see below.
Private Sub pvt_DefineTabControl()
Try
If Me.tabCont.Tabs.Count > 0 Then
Me.tabCont.Tabs.Clear()
End If
If Session("Counter") Is Nothing OrElse Trim(Session("Counter")) = String.Empty Then
Session("Counter") = 1
End If
For intI As Integer = 0 To CInt(Session("counter")) - 1
Dim tabPan As New TabPanel
Dim btnPanelNumber As New Button
btnPanelNumber.ID = "btnPanel" & intI.ToString
btnPanelNumber.Text = "Click me to create Panel " & (intI + 1).ToString
AddHandler btnPanelNumber.Click, AddressOf MyButtonClick
tabPan.Controls.Add(btnPanelNumber)
tabPan.HeaderText = "Panel" & intI.ToString
Me.tabCont.Controls.Add(tabPan)
Next
Catch ex As Exception
Throw ex
End Try
End Sub
Step 4: here I have added one Button in Tab Panel for this I used a common Click event handler which is MyButtonClick
By default there is a single TabPanel when you click button in tab Panel then you will get next panel.
Private Sub MyButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Session("Counter") = Session("Counter") + 1
Dim strButtonId As String = CType(sender, Button).ID
Dim intId As Integer = CInt(strButtonId.Replace("btnPanel", 0))
Me.pvt_DefineTabControl()
Me.tabCont.Tabs(intId).HeaderText = "You have Clicked me" + intId.ToString + "Panel's Button"
Catch ex As Exception
Throw ex
End Try
End Sub

Step 5:- For Example you can visit on http://indiadotnetajaxtabwork.tk/

and download code also.

Thanks & Regards
Rajat
Enjoy Coding :)
Enjoy Ajax tool kit :)

for more information http://www.indiandotnet.wordpress.com

Sunday, March 01, 2009

Asp.net with Ajax Basic

------------
1. What is Ajax ?
Answer: Ajax Stands for Asynchronous JavaScript And XML. It’s a way to make web application like windows application, give use rich Interface.


2. How it Works ?
By working as a extra layer between user browser and server it handle server communication in background submit server request take response from server, the response data integrated in page seamlessly without post back of page. This layer often refers as AJAX engine or AJAx framework.
When ever you click on link or submit form by pressing button then you make a http request. So the page is post back.
XMLHttpRequest is object that can be handle with JavaScript and we can achive goal to take http request without postback.
When we using AJAX layer then we do asynchronous post back which means request to server made in background
The flow is as follows
Web page Request --> Make xml Http Request object -->
Send rquest to server -->
Monitor the request Status -->
Ready state Status -->
respond to client -->
get response-->
Process Return data

For any AJAX work you need to create a object of XMLHttpRequest for many browser you can create objects as follows
var request = new XMLHTTPRequest();
To achive same result in microsoft browser you have to do following thing
var request = new ActiveXObject("Microsoft.XMLHTTP");
But some different version use below definition
Var request = new ActiveXObject("Msxml2.XMLHTTP");
Or you can write as below
< script language ="JavaScript" type="text/script"
>
var request ;
function defineRequest(){
try {
request = new XMLHTTPRequest();
}
catch ( ex) {
try{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (ex1){
try{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(ex2){
}
}
}

}

XMLHttpRequest object will have following property :
1) onreadystatechange :- Determine which event handler will called when object ready state property changed
2) readyState :- there are following values for this
0 - un initialize
1 - loading
2 - loaded
3 - intractive
4 - completed
3)responseText :- Data return by Server in text format
4) responseXML :- Data return by server in XML format
5) status : - Http Status code
6) statusText :- Http Status Text

And it has following methods
Abort() :- Stop the current Request.
getAllResponseHeaders() :- Return all headers as string
getResponseHeader(x) :- get the x header value in string
Open('Method',url, a) :- specify the Method post /get
url for request
a= true/false determine whether the request handle asynchronously or not.
Send(content) : send a request ( default post data method)

3. Basic Example
As part of AJAX basic I just come with below example in this we create two page one is with server coding & another with client coding.
My main aim here to get result by ajax with out post back so we just try to get current time as result.
For this we write code in default.aspx page as below
<
script language ="javascript" type="text/javascript"
>
var myServerRequest;
function callAjax() {
try {
myServerRequest = new XMLHttpRequest();
myServerRequest.status

}
catch (ex) {
try {
myServerRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (ax) {
try {
myServerRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (ax1) {
return false;
}
}
}
}
function Callserver() {
callAjax();
if (myServerRequest != null) {
myServerRequest.open('GET', "serverCode.aspx", true);
myServerRequest.onreadystatechange = myServerResponse;
myServerRequest.send();
}
return false;
}
function myServerResponse() {
if (myServerRequest.readyState == 4) {
if (myServerRequest.status == 200) {
document.getElementById('dvResult').innerHTML = myServerRequest.responseText;
} else {
document.getElementById('dvResult').innerHTML = 'Oops Error';
}
}
return false;

}
script
>
Here we have 3 main function
1. CallAjax :- it is responsible for Assigning XMLHttpRequest Object.
2. myserverResponse :- by the name it is clear that it use for holding the result what ever pass by server.
3. callServer :- This function is call on any event on button and it sum up the above 2 events.
On server Page at page load we do following code

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Write(Now.ToString)
Response.End()
End Sub
Here we just write time as response then we end response.

If you do not do response.end() then html of server page also comes.

5. What is JASON ?
Ans: JASON is JavaScript Object Notation. It’s a light weight Data interchange format which is independent from language. Its easy to read & Write by human & easy to parse & genrate by language. The attributes is seprated with "," (comma) and value of attributes are define after colon symbol(":") .
Ex:- {Data:[{"fname" : "RAJAT", "Lname" : "JAISWAL" }]}
The above is JASON example in which there are two attributes fname, Lname and the are seprated by "," (comma) symbol.
And there value is "RAJAT" & JAISWAL" which are define after ":" (colon)symbol.

for more information just copy paste "http://indiandotnet.wordpress.com/category/aspnet/ajax/"

Thanks
Rajat Jaiswal

Tuesday, December 16, 2008

Asp.net Ajax Panel Performance

Hello friends,

let start with some perfomance improvement tips which i used and it improved performance too.

but before starting it be sure that u have restored Vs2008 sp1.

It will give many new functionality.

today's tips is Load Script befor Ui property in scriptManager tag of ajax.

when you use the LoadScriptsBeforeUI="false" then Script is load first then javascript dowloaded on client site due to which performance at user end is improved.

Secondly if you require partial page rendering that use it EnablePartialRendering="true"

just because of it your performance will improved.

you can use both the otption as shown below.




Thanks

Rajat