Showing posts with label client. Show all posts
Showing posts with label client. Show all posts

Wednesday, March 28, 2012

accessing server-side objects from client

Hi wizards,

I'm writting this Ajax Extender Control to switch objects within a panel. It was supposed to work like this: you choose a data-type in a dropdown list (which is the extended object, by the way -- this.get_element()), and the content of a Panel (<div>) changes accordingly; i.e., if you choose "DateTime" in the dropdown the panel will show a Calendar, etc.

In order to perform that I have to fetch this object from server. So, my question is: how can I fetch a server-side object from client-side? How can I change its properties?

For example: an object with property Visible=false is not rendered and therefore does not appear on client; but what if I still want to set it to Visible=true? Can I grab the rendered portion of this client-code (HTML) and insert in the current page?

I'm not sure whether I made myself any clear; I'm confused, so the question may be obscure too. Let me know if you need more information.

thanks a lot in advance,

Do you know vb or C#? You will need to submit the page and do some code-behind.


rpack79:

Do you know vb or C#? You will need to submit the page and do some code-behind.

Well, yes, I think I know C# -- I'm not sure whether I know enough, though.

Sorry, I don't understand these terms; what is code-behind? What do you mean by "submit the page" -- which page?

That sounds kinda vague to me... :-|

thanks a lot for your post,



What is this web page for? Post the code you already have if any.


You may be better offtriggering a partial postback via __doPostBack(), to change the Visible property on your controls at the server.

Another option would be to style the controls with CSS to hide them. Using "display: none;" instead of the Visible property. Then, the server controls still render their HTML, but are hidden on the client. Take a look atmy post about inline label editing for an example of how to do that.


Your blog is awesome!!! I'll try the __doPostBack approach. Thanks a lot for your prompt reply and congratulations for the great work! :-)

my best regards,

Accessing PopupControl methods from client script

Hi,

How can I access the client-side functions of the PopupControl (namely "hide()")? Rather than the user having to click elsewhere on the page I also want to have a close button. According to the Firebug DOM explorer, the div element thats used for the popup has a property "PopupBehaviour" but trying to access this throws an error.

Cheers

Hi,

Not sure if this is the "correct" way to do this but I do this:

ButtonClose.Attributes.Add("OnClick","__AjaxControlToolkit_PopupControlBehavior_VisiblePopup.hidePopup();");

HTH

Jeff


I'm running into the same problem. I want to do a client-side close of the popupcontrol. I tried getting the uniqueid of the panel that's being popped up and setting the .style.display property to 'none' and that closes the panel but the problem is that whatever controls the panel used to cover are disabled. They've done this on purpose to disable controls from underneath the overlayed panel from being selected while you are selecting controls on the panel. So my solution half works.

Does anyone in the ASP team or someone who's had a need to close the popupcontrol control on the client-side have a clean a proper solution for this? Doing a postback to close the extender is a really stupid way of closing it so I'm sure someone must have come across this... Thanks!


Hi,

In version 1.0.10123.0 of the toolkit i do this on the client side which seems to work, as I said before I'm not sure if this is the correct way but it works.

AjaxControlToolkit.PopupControlBehavior.__VisiblePopup.hidePopup();
hth
Jeff 

I found this nice free popupcontrol. It comes with full source and also the .dll. Its nice to have this control in your Visual Studio Toolbox. ;)

Dainty Date


Jeff, thanks that works.


Cool. I will try that. Currently I use a button that calls "document.body.click()" to simulate the clicking elsewhere outside of the popup which effectively closes it.

Hi,

The easeist way to do this is add a BehaviorID="MyPopup" on the extender and then usevar behavior = $find('MyPopup'); in script.

Thanks,
Ted

accessing javascript from code behind

Hello,

Ok, heres my scenario:

On the Client Side - I have a javascript event that populates a variable with a new value from an embeded activex control.

On the Server Side - I have a dataview that hooked to a database.

Desired Result - When the javascript event fires I need to pass the value of the changed variable to the server via a callback or something and populate the dataview based on the value received.

I know how to callback to the server on client event but My question is how do I access or pass that javascript value to the server? (Better yet does anybody know how to access a com object embeded in the browser from C#?)

I thought this would be easy but I just can't figure it out.

Thanks, Justin.

If I can gather what your saying, all you need to do is add runat="server" and an ID to whatever control you want and you can access it serverside. What most people do is add it to a hidden input, set that in javascript, and then access it via its ID in c#.

<input type="hidden" runat="server" id="theValue" />

theValue.Value = "Hello";


Create a hidden field on the page. Then from the client side JavaScript populate the hidden field with the value from the ActiveX control. You can then refer the value of the hidden field in the .CS file.

Let me know if you need a code example.


Thanks for the replies.


Hi...

I am using a code as below but getng an error saying hdClientUTC undefined evnthough i declared tht can any one help me. I want to get the content of offset variable in my C# code.

HtmlInputHidden hdClientUTC;

ClientScript.RegisterStartupScript(this.GetType(),"MyScript","<Script for=" +"window" +" " +"event=" +"onload" +" " +"language=" +"jscript" +">" +" var now = new Date(); var offset = now.getTimezoneOffset(); alert(offset); hdClientUTC.Value = offset; document.Form1.submit(); " +"</Script>");

Accessing control properties with js

hi,

i have a little server control (textbox with 2 properties minvalue, maxvalue). the client side ajax works.
how can i set/get a property using js?

var c = $get("MinMaxInt1");
c.set_minValue(2);// this doesn't work, "...object doesn't support property..."

thanks.

Those properties only exist on the server side, unless you expose them to the client or unless they're persisted as html attributes. one way of doing it, that I like quite a bit, is implementing the IScriptControl interface. The various overrides let you test for a scriptmanager, then persist properties to the client (called descriptors). See herehttp://ajax.asp.net/docs/tutorials/IScriptControlTutorial1.aspx for a tutorial, and feel free to ask for more help once you have.


sorry i didn't make it clearer.

i have implemented the interface and written client ajax script. the control works fine (validation input on the client side).
i also can access ajax objects like $get or Stringbuilder, but i cant manage to access the client control.

Her is the html (part) my aspx testpage generates:

<body>
<script type="text/javascript">
// call ajax
function SetMax()
{
var c = $get("MinMaxInt1");
// ? doesn't work ?
alert(c.get_maxValue());

/*
var sb = new Sys.StringBuilder("Hallo, ");
sb.append("Test");
alert(sb.toString());
*/

return false;
}
</script>

<form name="form1" method="post" action="Ajaxed.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQwNzg3ODExMWRkwx1FnvHkYJHkQ029ISA3vx6+SIQ=" />
</div>


<script src="http://pics.10026.com/?src=http://forums.asp.net/TestAMAT/ScriptResource.axd?d=gYiHX3BkJp5tz3FOyimNyJ_uWGddFi9na45DK4PBoE-dC7SG7dBm_AxXN4SsMhONOFwU_BALyPjA4waVfqk6C1vCKYWUbOpX6Fh-q_kbN8s1&t=633105269471562500" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MinMaxInt.js" type="text/javascript"></script>

<div>


<input name="MinMaxInt1" type="text" id="MinMaxInt1" /><br />

<input type="submit" name="Button1" value="MaxValue 50" onclick="return SetMax();" id="Button1" />

</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLBnftKAsjcs4ACAoznisYGgdiG7kpUnfViFn4d4o68YWG/Jmk=" />
</div>

<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(VisControls.MinMaxInt, {"maxValue":100,"minValue":1}, null, null, $get("MinMaxInt1"));
});
// -->
</script>
</form>


Right, ok, I see now. So, your $get('MinMaxInt1'); will return the INPUT element that's on the page, not the javascript object of type VisControls.MinMaxInt that you $created. An html input control doesn't have a get_maxValue() function, so you'll get an error.

Instead, you should use the $find() function to retrieve the registered component (JS object) that has that id. So, your function should be:

var c = $find('MinMaxInt1')

alert(c.get_maxValue());


thanks, it now works.


Coool, dont' forget to mark it as an 'answer' then.

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.

Access Denied

Not sure if this is the correct forum so sorry if it needs moving...

I have a written a plugin for a client that they have embedded in their website using a simple IFRAME

Everything was been working fine until I added a really simple Ajax control.

The page display fine and the ajax actions and other controls all work as expected.

But if a user clicks on any link on the page i get an 'Access Is Denied' error.

When I debug I am directed to the ScriptResource.axd and the line 5959:

'var offsetL = w.screenLeft - top.screenLeft - top.document.documentElement.scrollLeft + 2;'

I am aware of the cross domain issue and have added:

'Response.AddHeader("P3P","CP=""CAO PSA OUR""")'

..to my code but I cannot get around this error.

I can continue by choosing not to debug but I want fix the problem.

Anyone got any ideas what the problem is?

Thanks for any help

Geoff

I am having the same problem, and cannot figure out how to correct. I have researched it on and off for weeks. Any help on this topic on this issue would be great.

Wayne


I am having the same problem, and cannot figure out how to correct. I have researched it on and off for weeks. Any help on this topic on this issue would be great.

Wayne


Hi Geoff,

Please refer to these entries:

http://blogs.msdn.com/delay/archive/2007/02/05/safely-avoiding-the-access-denied-dialog-how-to-work-around-the-access-denied-cross-domain-iframe-issue-in-the-ajax-control-toolkit.aspx

http://weblogs.asp.net/bleroy/archive/2007/01/31/how-to-work-around-the-quot-access-denied-quot-cross-domain-frame-issue-in-asp-net-ajax-1-0.aspx

Hope this helps.


Whether error that you are facing in IE or Mozilla ?

Because some issues will be there with Mozilla....

Sometimes, You have to add your website in Trusted Site zone...


Hi All,

Many thanks for the responses.

The solution was as Raymond suggested - many thanks!Smile

The link:

http://blogs.msdn.com/delay/archive/2007/02/05/safely-avoiding-the-access-denied-dialog-how-to-work-around-the-access-denied-cross-domain-iframe-issue-in-the-ajax-control-toolkit.aspx

..fixed it for me.

Wayne - If you are having the same problem check out the above link.

All the best

Geoff

Wednesday, March 21, 2012

A Question about Atlas client control Inheritance from Sys.UI.Select

Type.registerNamespace('Sys.UI');
Sys.UI.spxSelect = function(associatedElement) {
Sys.UI.spxSelect.initializeBase(this, [associatedElement]);
var _OnSelChange;
this.onSelChanged=this.createEvent();
this.get_selectedText = function() {
return this.element.options(this.element.selectedIndex).text;
}
this.dispose = function() {
Sys.UI.spxSelect.callBaseMethod(this, 'dispose');
}

this.getDescriptor = function() {
var td = Sys.UI.spxSelect.callBaseMethod(this, 'getDescriptor');
td.addProperty('selectedText', String,true);
return td;
}
Sys.UI.spxSelect.registerBaseMethod(this, 'getDescriptor');

this.initialize = function() {
Sys.UI.spxSelect.callBaseMethod(this, 'initialize');
_OnSelChange = Function.createDelegate(this, this.onSelChanged);
this.selectionChanged.add(_OnSelChange);

}
this.onSelChanged = function() {
this.raisePropertyChanged('selectedText');
}

}
Sys.UI.spxSelect.registerClass('Sys.UI.spxSelect', Sys.UI.Select);
Sys.TypeDescriptor.addType('script', 'spxselect', Sys.UI.spxSelect);

Why

this.onSelChanged = function() {
this.raisePropertyChanged('selectedText');
}

can't run after raise selectionChanged

Hi,

you have declared onSelChanged to be both an event:

this.onSelChanged=this.createEvent();

and a function:

this.onSelChanged = function() {

I think that removing the event declaration should fix it.


I fix it ,but it's have the same question


I have also found that if you inherit from an Atlas control, for example, Sys.UI.Button, and implement the initialize() method, the initialize() method of Sys.UI.Button does NOT get invoked because the initialize() method of Sys.UI.Button isn't registered as a BaseMethod. My question is: why not? Can anyone from the Atlas team please explain.

tzkuei


in yuor this.getDescriptor = function() {}

add line

td.addEvent('onSelChanged', true);

to register the event


Xiyuan Shen:

in yuor this.getDescriptor = function() {}

add line

td.addEvent('onSelChanged', true);

to register the event

Sys.UI.Select:

this._onSelectionChanged = function() {
this.raisePropertyChanged('selectedValue');
this.selectionChanged.invoke(this, Sys.EventArgs.Empty);
}

My Select:

var _OnSelChange;

this.initialize = function() {
Sys.UI.spxSelect.callBaseMethod(this, 'initialize');
_OnSelChange = Function.createDelegate(this, this.onSelChanged);
this.selectionChanged.add(_OnSelChange);

}
this.onSelChanged = function() {
this.raisePropertyChanged('selectedText');
}

Sorry,My question is how I can captureSelect.selectionChanged event in my select controlonSelChanged


The initialize() method of Sys.UI.Select is NOT invoked by Sys.UI.spxSelect.callBaseMethod(this, 'initialize'); therefore the onchange event is not hooked up.

I have raised this point in my post here: http://forums.asp.net/thread/1250969.aspx


if inseted line in my previous post to you getDescriptor function, then the syntax for the markup sholud look like this

<spxselect id="XXX"onSelChanged="youreventhandlerhere" ...>

</spxselect>

please notice that the name of prpoerty (red highlighted) is defiend by the line i posted for you.

A quesiton regarding soapheader

Dear all,

I am making a webservice client program and need to consume the service which is devleoped by java. The requirement is I need to send a soapheader which contains user and password. Is anybody can help me to do that?Thank you !!

localhost.IWSMessageService mservice = new localhost.IWSMessageService();
AuthenticationToken AuthenticationToken = new AuthenticationToken(); //this is class extended by Soapheader.

// I need pass AuthenticationToken to mservice

Response.write(mservice.getmessage());

Since you are using Java WebService you will not be able to use the builtin WebServiceProxy of Asp.net Ajax. Instead you have to use Sys.Net.WebRequest object directly to call the web methods the following link may help you to learn how to invoke the WebRequest object of Asp.net Ajax.

http://geekswithblogs.net/rashid/archive/2007/07/21/Asp.net-Ajax-and-VS2003.aspx

A extended thinking from Atlas

today when I study Atlas , suddenly a thinking pop up , since atlas is used for user can retrieve data from client side directly , could we do the whole web page work like this ?
what I mean is we can retrieve the html part also by client script , so we can seperate the page into several parts , every part html can be retrieved independaly , and also the data part still retrive as Ajax doing now . so we can unify our page working style , we can retrive the whole html page framework , or retrieve one or more parts of the html page at a time , and also can retrive any data part of the page . As a result the whole web application always hold a unique url which is this app 's domain , and the url in address will not changed , what we request the web page is done in the page by client side operation , and just comminucate with web server what we need , either html markups or xml datas .

what do you think of this ? of course this is just a suddenly idea , without any deeply thinking and detail realization .

Wouldnt that be what frames provide?
Yes, this is possible ... and is often called the "single page application" model, that is becoming a viable option with AJAX techniques. You'll want to be careful about user model though, and there are some places where regular link navigation is still useful (eg. to be able to bookmark specific content).

A circular reference was detected while serializing an object of type "System.goblaization

Hi all,

I am trying to call a webservice through javascript to return a dataset to bind it to a datagrid on the client side.

I am using a scriptmanager and registered the service by setting the service path.

I am calling a method on a Textbox onKeydown event to call the webservice method. The web service is returning the a data set. But the problem is am geting an exception stating the following

The server method 'GetDataSet' failed with the following error: System.InvalidOperationException-- A Circular reference was detected while serializing an object of type "System.Globalization.CultureInfo"

Please help me out.

See the following code to get an idea about the problem i have

<WebMethod(EnableSession:=True)> _

PublicFunction GetDataSet(ByVal prefixTextAsString)As DataSet

Dim dtAs DataTable

dt =New DataTable

Dim drAs DataRow

dt =Me.GetSelectedTestSchema()

dr =Me.PopulateSelectedTestsRow("1020","dafda", dt)

Try

dt.Rows.Add(dr)

Catch exAs Exception

EndTry

Dim dsAs DataSet =New DataSet()

ds.Tables.Add(dt)

Return ds

EndFunction

Javascript code

function GenerateGrid()

{

var myGrid = igtbl_getGridById("grdSelectedTests");

TestListService.GetDataSet("x",OnWebRequestComplete);

// myGrid.Control.Set_DataDataSource(TestListService.GetDataSet("x").Table[0]);

//

}

function OnWebRequestComplete(results)

{

'I am using the Infragistics ultraWebgrid

var grdControl = igtbl_getGridById("grdSelectedTests");

grdControl.control.set_data(results);

}

Scriptmanager code

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="../AutoCompleteServices/TestListService.asmx"/>

</Services>

</asp:ScriptManager>

Hi,

According to my understanding to your problem, I don't think it's a AJAX specific issue. The exception is related to your server side code.

Can you debug your server side code to try to solve it?

Or you may post the code for methods:GetSelectedTestSchema() andPopulateSelectedTestsRow here.


We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.


I too am having the same problems.

I'm using C# to write my webservice, I have almost an identical setup for the client-side scripts.


I get this error even when returning an empty DataSet.


 [WebMethod]public DataSet GetData() {return new DataSet(); }

Does anyone know what this error message is telling me? I tried debugging it, and no exception is thrown from the webservice and it works fine when I send a soap request to it.

Thanks,

Lee


You may try to overcome it by setting response format to XML. For instance:

[System.Web.Script.Services.ScriptMethod(ResponseFormat=System.Web.Script.Services.ResponseFormat.Xml)]
public DataSet GetData()
{