Showing posts with label xml-script. Show all posts
Showing posts with label xml-script. Show all posts

Monday, March 26, 2012

Detecting point of click on Table

Hi all.
I have a Table on my page. By xml-script I can detect clicks on it.

<components>
<button id="Table1" click="DoSomething" />
</components
But I want to know coordinates of the point on this table, which was clicked. Specifically I want to have them in my function "DoSomething()"
Please, help me.

There are examples here for tracking mouse position:http://www.irt.org/script/pointer.htm

-Damien


DoSomething should be a function like so:

function DoSomethign(ev){}

ev.clientX and ev.clientY will give you the coordinates, and so on.

Wednesday, March 21, 2012

Declarative xml-script from UpdatePanel

Is there a way to insert (and execute) declarative xml-script from UpdatePanel?

For example following code works if control is visible, so xml-script is loaded with the page. If control is hidden, or created at run time xml-script is not executed.

test.aspx:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" %>
<%@dotnet.itags.org. Register TagPrefix="uc" TagName="Control1" src="http://pics.10026.com/?src=~/WebUserControl.ascx" %>
<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
c1.Visible = true;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"><title>Untitled Page</title></head>
<body>
<form id="form1" runat="server">

<atlas:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />

<atlas:UpdatePanel ID="p1" runat="server" Mode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<uc:Control1 ID="c1" runat="server" Visible="false" />
</ContentTemplate>
</atlas:UpdatePanel>

</form>
</body>
</html>

WebUserControl.ascx:

<%@dotnet.itags.org. Control Language="C#" ClassName="WebUserControl" %>

<div id="panel">Click the button to Hide me</div>
<input id="hideButton" type="button" value="Hide" />

<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<control id="panel" />
<button id="hideButton">
<click>
<setProperty target="panel" property="visible" value="false" />
</click>
</button>
</components>
</page>
</script>

hello.

well, where's your panel control? if it's inside a user control, then you've already found your problem: the user control is a naming container class. this means that controls declared inside it will have a different client side id (it will be composed by the usercontrol id and the control id).


I thought client side id only changed for webform controls. This panel is just a plain <div>.

And if I just make user control visible from the start, it works, xml-script executes.


hello.

yes, if it's an html control, then you're right. not sure about the visibility...can you show me the div declaration that you have in the user control?


The div declaration is actually in the code above:<div id="panel">Click the button to Hide me</div>

I choose to hide div just for sample sake, it can be any xml-script.

Anyway, I recall now, javascript doesn't execute either, when it's inside control template and then the control instantiated inside update panel. The only way is to use RegisterXYZScript(...). But RegisterXYZScript(...) doesn't work for xml-script.

When using ScriptManager RegisterControl it places xml-script inside of that <xmlScript> tag at the end of update panel's <delta> response. I think it executes it, but there beside RegisterControl I didn't find any more methods to generate xml-script.

I know there is a way to write an ExtenderControl, and use ScriptTextWriter to generate xml-script. I haven't tried that yet.

Declarative WebService call

Hi everybody

I just tried to call a method with MS-Ajax and the xml-script ... but in some way it doesn't work ...

This is the code:

-----------


<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<label id="LbTest" /
<button id="BtTest">
<click>
<setPropertyAction target="LbTest" property="text" value="TestStarted" />
<invokeMethodAction target="CFCCall" method="invoke">
<parameters userContext="" />
</invokeMethodAction>
</click>
</button
<serviceMethodRequest id="CFCCall" url="Services/SCheck.asmx" methodName="Test.Web.CheckClass.Check">
<completed>
<setPropertyAction target="LbTest" property="text" value="TestCompleted" />
</completed>
<error>
<setPropertyAction target="LbTest" property="text" value="TestError" />
</error>
</serviceMethodRequest>
</components>
</page>
</script>

-----------

I got a check method in my checkclass in the webservice, which is in the namespace "Test.Web".

If I call this with JS directly, I'm getting my result - but if I'm doing it this way - I just get the "TestError" label-value. Any ideas?

Found the problem: It was the webservice - The webservice denies by default GET requests... does anyone know how I could switch the default method in xml-script to POST (i can't enable GET in the webservice, because I don't have access to it)... Or does someone know how I can call a Javascript in XML-script? Because with an JS I could make call and tell the call to use POST...

Declarative Script is parsed twice

When you start a new Atlas project, the code says at the end
" <script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
</components>
</page>
</script>
"
When you build the page, this piece of code is inserted twice (justlook at the source). Is there a way to prevent that, in other words,can't Atlas build his code in the existing script?
This is just a (little) waste of bandwidth

Hi,

That code is there just as a template to help you get started. The second copy of the script that you probably see is what gets rendered by the ScriptManager control.

You can just remove the static XML-Script tag if you're not planning on using it.

Thanks,

Eilon


I see, but wouldn't it be nice to merge the static XML with the XML rendered by the scriptmanager?

Currently the ScriptManager doesn't even know about the static XML script on the page since it doesn't have a runat="server" on it and there's no control that represents it. We're thinking of ways that we can merge these two concepts, and have some ideas, but nothing to show just yet :)

Thanks,

Eilon

Dec Preview CTP, xml-script and simple data binding

Ok my problem is not that my code doesn't work, it does, but it makes no logical sense and I was hoping someone could explain it to me.

The problem is that when data binding programatically, the steps are: create controls (say a textbox and a label), initialize them (sigh), create the binding object, set the properties of the binding, including specifying the label as "target". Here is the complete woking code for this:

// Create and initialize Controls

var textbox =new Sys.Preview.UI.TextBox($get("TextBox1"));
var label =new Sys.Preview.UI.Label($get("Label1"));
textbox.initialize();
label.initialize();

// Create binding

var binding =new Sys.Preview.Binding();
// Set properties and initialize
binding.set_dataContext(textbox);
binding.set_target(label);
binding.set_dataPath("text");
binding.set_property("text");

// Using a standard Transform

binding.add_transform(Sys.Preview.BindingBase.Transformers.ToString);
binding.set_transformerArgument("Text entered: {0}");
binding.initialize();

When you want to do the same thing in xml-script, the rules seem to change. You no longer set the "target" of the binding, but ad the binding to the "bindings" of the label itself. Here is the working code for that:

<

div>
<inputtype="text"id="TextBox1"/><br/>
<labelid="label1"></label>
</div>

</

form>
<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<components>
<textBox id="TextBox1" />
<label id="Label1">
<bindings>
<binding dataContext=
"TextBox1"dataPath="text"property="text"transform="ToString"transformerArgument="Text entered: {0}" />
</bindings>

</label>
</components>
</page>
</script>

According to "Programming Atlas" by Wenz, the way the xml-script is doing it is the way it *used to be done* in code. So to set the label as the target, you would have done this:

label.get_bindings().add(binding);

but now, thelabeldoes not have any methods that would support this, like "get_bindings().add" or "add_binding". The code above just fails "object does not support this property or method".

So why is this? Am I missing something? Ths is making no sense to me.

I should say that new APIs are hard enough to learn, but there is no intellisense, and I'm finding places where the API is inconsistant ("get_events" instead of "getEvents" - why the inconsistant camel casing?) And now stuff llike this...?

Also, does anyone know if the dec CTP and the stuff in the "Preview" namespace will be part of RTM1 ? Or will it continue as an unsupported preview. And also,where are the docs for the Preview objects?

Try to take a look at this materials about Futures Dec CTP for reference -http://ajax.asp.net/files/AspNet_AJAX_CTP_to_Beta_Whitepaper.aspx

Hi,

It seems that<binding dataContext="TextBox1"dataPath="text"property="text"transform="ToString"transformerArgument="Text entered: {0}" /> is not working as expected in RC1. ThetransformerArgument doesn't seem to work.

Any idea?

Vlad


Try this (working code snippet)

1<%@. Page Language="C#" AutoEventWireup="true" CodeFile="ControlBindingXmlScript.aspx.cs" Inherits="ControlBindingXmlScript" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">45<html xmlns="http://www.w3.org/1999/xhtml" >6<head runat="server">7 <title>Untitled Page</title>8<script>9function main()10{11 // Add Client Code here12}13</script>14</head>15<body>16 <form id="form1" runat="server">17 <asp:ScriptManager ID="ScriptManager1" runat="server">18 <Scripts>19 <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />20 <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewGlitz.js" />21 <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewDragDrop.js" />22 </Scripts>23 </asp:ScriptManager>24 <script>25 Sys.Application.get_events().addHandler("load", main);26 </script>27 <div>28 <input type="text" id="TextBox1" /><br />29 <label id="label1"></label>30 </div>31 </form>32 <script type="text/xml-script">33 <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">34 <components>35 <textBox id="TextBox1" />36 <label id="Label1">37 <bindings>38 <binding dataContext="TextBox1"39 dataPath="text"40 property="text"41 transform="ToString"42 transformerArgument="Text entered: {0}" />43 </bindings>44 </label>45 </components>46 </page>47 </script>48</body>49</html>50
"C#" AutoEventWireup="true" CodeFile="ControlBindingXmlScript.aspx.cs" Inherits="ControlBindingXmlScript" %>

Hi,

You are binding to a label not to a text box. This is still not working (where textBox is an asp:textbox):

<textbox id="textBox">
<bindings>
<binding dataContext="checkBoxBoolean"
dataPath="checked"
property="text"
transform="ToString"
transformArgument="Checkbox is {0}"
direction="InOut" />
</bindings>
</textbox>


Vlad


Hello.

this is working here

<%@. Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script>
function main()
{
// Add Client Code here
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
</Scripts>
</asp:ScriptManager
<div>
<input type="text" id="TextBox1" /><br />
<input type="text" id="text" />
</div>
</form>
<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<components>
<textBox id="TextBox1" />
<textBox id="text">
<bindings>
<binding dataContext="TextBox1"
dataPath="text"
property="text"
transform="ToString"
transformerArgument="Text entered: {0}" />
</bindings>
</textBox>
</components>
</page>
</script>
</body>
</html>

I've noticed that you're using INOUt for the direction of the binding. I think that the ToString transformer only allows you to specify the In direction.