XML Data Display




string connString = WebConfigurationManager.

ConnectionStrings[“adventureWorks”].ConnectionString;

The above line of code retrieves the connection string from the connectionStrings section of the

web.config file. The connection string is stored in the web.config as follows.

<connectionStrings>

<add name=”adventureWorks”

connectionString=”server=localhost;Integrated Security=true;
database=AdventureWorks”/>

</connectionStrings>

Once the connection string is retrieved, you then create an instance of the SqlConnection object passing
in the connection string as an argument. Then you create instances of DataSet, SqlDataAdapter, and

SqlCommand objects passing in the appropriate parameters to their constructors. Then you execute the

sql query by invoking the Fill() method of the SqlDataAdapter object. Once the query is executed
and the results available in the DataSet object, you then invoke the GetXml() method of the DataSet

object to return the XML representation of the DataSet to the caller. The GetCallbackResult() method
receives the output xml string and simply returns it back to the caller.

Generating the Client-Side Script for Callback

This section will look at the Page_Load event of the page. In the beginning of the Page_Load event, you
check to see if the browser supports callback by examining the SupportsCallback property of the

HttpBrowserCapabilities object.

if (!Request.Browser.SupportsCallback)

throw new ApplicationException

Then you invoke the Page.ClientScript.GetCallbackEventReference() method to implement
the callback in client-side. You can use this method to generate client-side code, which is required to ini-
tiate the asynchronous call to server.

string src = Page.ClientScript.GetCallbackEventReference(this, “arg”,   

“DisplayResultsCallback”, “ctx”, “DisplayErrorCallback”, false);

The arguments passed to the GetCallbackEventReference method are as follows:

  this— Control that implements ICallbackEventHandler(Current Page)

  arg— String to be passed to server-side as argument

  DisplayResultsCallback— Name of the client-side function that will receive the result from

server-side event

  ctx— String to be passed from one client-side function to other client-side function through

context parameter

  DisplayErrorCallback — Name of the client-side function that will be called if there is any

error during the execution of the code

  false— Indicates that the server-side function to be invoked asynchronously


learn guitarphysics learnteliphonyxmlphysicsenjoylife