Showing posts with label syntax. Show all posts
Showing posts with label syntax. Show all posts

Wednesday, March 28, 2012

Accessing Controls From JavaScript

What is the syntax for accessing control form javascript? I can't seem to find it anywhere - I thought it was something like

dunction HideOne(n)

{

var ele = Sys($(n))

}

not a lot to go on with what you have provided but...

assuming that "n" in this context is the id of an element you want to "access" or get then you should use "$(n)"
to avoid issues with that statement... in your example you would remove the Sys() part and only have the $(n) part

this all depends on, however, how you are creating your elements. if you are using the xml-script declarative approach then you might be better off using the $object() function.
the $object() function searches the current markup context for the element, then traverses the tree up to the Application level to try to find the element.
this is different than the $() function which is nothing more than a shortcut for "document.getElementById()"

this allows the ATLAS runtime to have (or support) multiple elements with the same "id" without violating the HTML 4.1 specifications stating "an elements id must be unique" which it clearly would be (in the current context)

hope that helps... if not try adding some more of your code so we can get a better understanding of what you are dealing with


That was perfect thanks.

Monday, March 26, 2012

Accessing complex data properties on the client side.

I'm trying to access the properties of an object passed back from a web service but am having trouble. I thought the syntax was...

results.getItem(i).getProperty(

'propertyname') but I'm getting an error 'results.getItem(i).getProperty' is not a function.

I'm able to bind 'results' to a listview fine on the client side and debug.dump shows the data being returned is correct.

i don't know what type 'results' is.
you can try to use code below to list methods and propertis of getItem(i)
function(obj)
{
for(var name in obj)
names+=name+"\n";
alert(names);
}

tonyqus:

i don't know what type 'results' is.
you can try to use code below to list methods and propertis of getItem(i)
function(obj)
{
for(var name in obj)
names+=name+"\n";
alert(names);
}

Sorry tonyqus, 'results' is a generic collection and the javascript function on the client returns '_serverType' and the property names of the objects (similar to debug.dump). If I return a datatable the following works fine.

for (var i = 0; i < results.get_length(); i++) { alert(results.getItem(i).getProperty("PropertyName"));}
Is there a way to do something similar with object collections? The object collection binds fine to a listview or select element using set_data(results) so there must be some way of referencing the properties in javascript.

Never mind:!

Came back to it today and looked a little closer at the response from fiddler for a datatable vs an object collection. Also looked a little closer at JSON (http://www.json.org/). The line results.getItem(i).getProperty("PropertyName") works with datatables where results[i].PropertyName works with collections.

Saturday, March 24, 2012

about syntax error!

error: syntax error
source document :http://localhost/MyDream/AboutConten.asmx/js
line:3
source code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

my AboutConten.asmx is:

<%@dotnet.itags.org. WebService Language="C#" Class="MyDream1.AbouConten" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace MyDream1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AbouConten : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string ShowContent(string myId)
{
int id = Convert.ToInt32(myId);
string connStr = ConfigurationManager.AppSettings[0].ToString();
SqlConnection conn = new SqlConnection(connStr);
string cmdStr = "select this_content from myTopic where this_id = @dotnet.itags.org.this_id";
SqlCommand comm = new SqlCommand(cmdStr, conn);
comm.Parameters.AddWithValue("@dotnet.itags.org.this_id", id);
conn.Open();
SqlDataReader dr = comm.ExecuteReader();
dr.Read();
string returnStr = dr[0].ToString();
dr.Close();
conn.Close();
return returnStr;
}

}
}

why?

please help me!

thanks!

What do you see when you navigate to the proxy directly from the browser (typehttp://localhost/MyDream/AboutConten.asmx/js in your address bar)?