Showing posts with label extender. Show all posts
Showing posts with label extender. 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 inherited behavior properties

Hello,

I've created a new extender who's behavior class in the javascript file inherits from an existing control (in this case the cascading drop down) and registered it like so:

CustomCascadingDropDown.CustomCascadingDropDownBehavior.registerClass(
'CustomCascadingDropDown.CustomCascadingDropDownBehavior', AjaxControlToolkit.CascadingDropDownBehavior
);

I'm listening for the selectedValue property change event to occur so that I can access the resulting value and operate on it but when I try to access it from my inherited behavior class as this._selectedValue I get a null value. If I try using the callBaseMethod method to access the property accessor I get a different exception. How do I access inherited properties?

Also, what is the correct procedure for attaching to property changed events? I assumed from other posts that is by using this.add_propertyChanged(handler) but is this correct? How does this attach itself to a specific property or does it just enumerate through all properties that have been changed?

Thanks in advance.

Hi,

can I see the code that you're using to handle the event?


Sure thing... thanks for the help by the way.

The code below is just a test. I just want to see if I can access the inherited property.

First I attach a handler to listen for the property changed event in the initialize method of my custom behavior:

initialize : function() {
PersistentCascadingDropDown.PersistentCascadingDropDownBehavior.callBaseMethod(this, 'initialize');
this.add_propertyChanged(this.test);
},

Again, I'm not sure if this is the correct way to attach a handler to the propertyChanged event. It is only an assumption (how exactly do I target only one of the many properties that raise propertyChanged events?).

Next is my event handling method.

test : function (sender, args)
{
if (args._propertyName == "SelectedValue")
{
// Throws an exception
alert(PersistentCascadingDropDown.PersistentCascadingDropDownBehavior.callBaseMethod(this, 'get_SelectedValue'));

// Alerts as undefined
alert(typeof(this.get_SelectedValue));

// Alerts that object doesn't support method
alert(this.get_SelectedValue());
}
},

Thanks again for your help.

Accessing control extender behaviors in javascript

Hi there,

I'm using the AJAX 1.0 Beta 2 extensions and the AjaxControlToolkit. I'm finding it extremely hard to access the behaviors associated with a given control. (I'd like to hook into the expandComplete event of an CollapsiblePanel).

I've tried using the following:

var cp = $get('IdOfMyCollapsiblePanel');
cp.get_behaviors()[0].add_expandComplete(MyHandlerFunction);

This results in an error with the get_behaviors() call.

Can anyone post an example of how to hook up a javascript method to an extenders event? (client-side)

I'd really appreciate it!

Jeremy

And here I go replying to myself...

I found the source of my problem. I was trying to set up the event handling in the pageLoaded event that is raised by the PageRequestManager, but the behaviors are not yet loaded at this time. Instead I hooked the Sys.Application.load event and everything works!

Jeremy

Monday, March 26, 2012

Access Denied error when attempting to consume web service

I am attempting to call a web service from my extender control, but when I do so, I get an error message - access denied (there are no other details). After some research, I think this has something to do with cross site scripting - since the web service exists elsewhere (it is a public webservice). How does one access an external webservice?

Here is the code that is throwing the error:

Sys.Net.WebServiceProxy.invoke(this.get_servicePath(),this.get_serviceMethod(),false, params,

Function.createDelegate(this,this._onMethodComplete),

Function.createDelegate(this,this._onMethodFailed));

ServicePath="http://www.webservicex.net/uszip.asmx"ServiceMethod="GetInfoByZIP"

Check out this article:

http://dotnetslackers.com/columns/ajax/MashitUpwithASPNETAJAX.aspx

Hope this helps,

Elias.

Saturday, March 24, 2012

a sample project using AJAX

Hi,

i am doing a sample project to use Hovermenu extender..i have taken a lablebox whenever i will take mouse over it , it can be editable..but it is showing error

"DynamicControlID must be set"

This is code...

protectedSub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Load

Label1.Text = DateTime.Now.ToString()

EndSub

ProtectedSub Button1_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

EndSub

<System.Web.Services.WebMethodAttribute()> <System.Web.Script.Services.ScriptMethodAttribute()>PublicSharedFunction GetDynamicContent(ByVal contextKeyAs System.String)As System.String

EndFunction

<formid="form1"runat="server">

<div>

</div>

<asp:ButtonID="Button1"runat="server"Style="z-index: 100; left: 49px; position: absolute;

top: 200px"Text="Click"/>

<asp:LabelID="Label1"runat="server"Style="z-index: 101; left: 59px; position: absolute;

top: 28px"Text="Label"></asp:Label>

<cc1:ConfirmButtonExtenderID="ConfirmButtonExtender1"runat="server"

TargetControlID="Button1"ConfirmText="R u Sure">

</cc1:ConfirmButtonExtender>

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

</asp:ScriptManager>

<cc1:HoverMenuExtenderID="HoverMenuExtender1"runat="server"DynamicServiceMethod="GetDynamicContent"

TargetControlID="Label1"PopupControlID="label2">

</cc1:HoverMenuExtender>

<asp:LabelID="Label2"runat="server"Style="z-index: 103; left: 127px; position: absolute;

top: 171px"Text="hi"></asp:Label>

</form>

Kindly check it,

Regards,

Suryansu

To fix the error "DynamicControlID must be set" you should remove the attribute DynamicServiceMethod="GetDynamicContent"

That will solve error.Still then you will not be able to edit the label .To achive the effect you need follow the below script.

For futrher infiormation refer to the below link

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx

One possible way to implement your requirement is as like below

<form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Hover Me"></asp:Label>
<div runat="server" style="background-color: Yellow; width: 50px; height: 50px" id="popup">
<asp:TextBox ID="txtLabelContent" runat="server"></asp:TextBox>
<asp:Button ID="btnChangeTheLabel" OnClick="btnChangeTheLabel_Click" runat="server" Text="Set the Label Text" />
</div>
<ajaxToolkit:HoverMenuExtender PopupControlID="popup" TargetControlID="Label1" ID="HoverMenuExtender1"
runat="server">
</ajaxToolkit:HoverMenuExtender>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>

in the server side implement this

protected void btnChangeTheLabel_Click(object sender, EventArgs e)
{
Label1.Text = txtLabelContent.Text;
}


If you get an answer to your question, please mark it solved so people don't waste time reading already answered questions!


Thanx

Wednesday, March 21, 2012

A question for all - popup extender and popup control extender

I have three questions for the great participants of this forum who are regulalry helping people with their knowledge - Knowledge sharing is always great.

Anyways my questions are

1. What is the difference between popup extender and popup control extender?

2. Why I am unable to attach a popup control extender with a link button. Infact I do not want to return the value into a text box, rather I want to show the calender control when link button is clicked. Then on the selection changed event of the calendar, I will set a public property with the returned value, that will be assigned to another text box. But I get error.

3. where I can find detail documentation/book/link on ajax tool kit, with example and explaining different properties.

Three times thanks

Hi Akber,

1. The PopupControlExtender actually builds on top of the PopupExtender (if you look in the JavaScript code, you'll see it creates one). The PopupExtender is a simple utility to display one element as a popup of another. The PopupControlExtender adds additional features so the result of whatever happens in the popup can be passed to the control it was attached to (for example, if you have a textbox which pops up a calendar, you'll want to fill the textbox with the selected date when the popup closes).

2. Is your LinkButton causing a postback before the popup is displayed? What's the error message you're getting? I'd try adding an OnClientClick="return false;" to the LinkButton and see if that helps.

3. The best place to look is thewebsite and theToolkit source itself.

Thanks,
Ted