Showing posts with label ive. Show all posts
Showing posts with label ive. Show all posts

Wednesday, March 28, 2012

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.

Monday, March 26, 2012

Access page viewstate from static method?

Does anyone know how to grab the current Session, or Viewstate from within a public static method? I've got some WebMethods and I'd like to get the page context once inside of the server-side method.

Thanks,
Mark

You can access the Session, but not the ViewState.

Inside a static method, you need to reference the Session like so: HttpContext.Current.Session


You can also pass EnableSession=true to the WebMethod attribute, but honestly I'd strongly recommend just sending the values up the pipe if at all possible (as params).

Access Objects in diferent webControl

Hello,

I've been wondering if it's possible to manipulate objects from a webcontrol inside the vb code of diferent webcontrol.

Mainly what I'm trying to archieve is the usage of AJAX and its async triggers. I have a list of items, each with a button associated, all created at runtime, and I want to make them triggers of a shopping bag located inside an updatePanel on a different webcontrol that is already loaded inside the same page.

Is this possible? If so, how?

Thx

You can add you controls to the UpdatePanel's trigger collection which will cause these to update the UpdatePanel, seehttp://morewally.com/cs/blogs/wallym/archive/2006/09/20/359.aspx

-Damien


Hi,

Here:Trigger PostBack to an UpdatePanel from a separate UserControl?

A example for you to do this.

Best Regards,

Wednesday, March 21, 2012

A premium AutoComplete for AJAX?

Is there anyway to emulate the complete functionality of the comboBox control in MS Access that includes Autocomplete, column headers etc? I've seen some 3rd party ones, but am not at liberty at my company to acquire them.

I've used the autocomplete extender but I really need the column headers and "not-in-list" event. I was thinking I could use a datagrid or datalist to emulate this.

hi,

check this

http://ajax.asp.net/ajaxtoolkit/AutoComplete/AutoComplete.aspx


I'm sorry. I guess I should have mentioned thathttp://ajax.asp.net/ajaxtoolkit/AutoComplete/AutoComplete.aspx was mystarting point.
Presently, I am showing Cost Center numbers in one column. What I would like to do is have an additional column that displays a name description. If I were to add yet a third column, which is a possibility, it would just be nice to be able to display the column headers just as you do in Microsoft Access.


Here's what I have so far in the autocomplete.asmx (ONE column) , please help me adjust this for additional columns.

<%@.WebServiceLanguage="VB"Class="autocomplete" %>

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _

PublicClass autocomplete
Inherits System.Web.Services.WebService

<WebMethod()> _

PublicFunction GetSuggestionsFromDataset(ByVal prefixTextAsString,ByVal countAsInteger)AsString()

' Define data set

Dim dsAsNew DataSet()
Dim dtAsNew DataTable()
Dim drAs SqlDataReader = PurchasingBLL.GetCostCenters
Dim daAsNew PurchasingTableAdapters.tbl_CostCenterTableAdapter ds.Tables.Add(dt)
dt.Columns.Add(New DataColumn("Word",GetType(String)))
dt.Rows.Add("Cost Center")

DoWhile dr.Read
dt.Rows.Add(New ListItem(dr("FullCCNum")))
Loop

Dim suggestionsAsNew List(OfString)()
Dim wordsAs DataRow() = dt.[Select]("Word LIKE '" + prefixText +"%'")
Dim numAsInteger = IIf((words.Length < count), words.Length, count)

For iAsInteger = 0To num - 1
suggestions.Add(DirectCast(words(i)("Word"),String))
Next

Return suggestions.ToArray()

EndFunction

EndClass

I suppose I could put a "label" or something underneath the textbox, but I notice that the extender attaches exactly "Flushed" at the bottom, so I probably have to do some trickery to make that happen. Any suggestions?


This is not currently supported. We do want to allow users to set custom datatypes in the autocomplete flyouts bound to item templates but we are still investigating that approach.


Ok, then what about something less daunting like perhaps just helping me add another column in the web service?
I'm confused of the exact useage of the array ("suggestions") that was provided in the example.

I tried this, but it still only returns one column, - and as you can see, I haven't touched the "Suggestions" array.
Or -- is adding column headers specifically what is not supported?

dt.Columns.Add(New DataColumn("Word",GetType(String)))
dt.Columns.Add(New DataColumn("Descr",GetType(String)))

dt.Rows.Add("Cost Center")
DoWhile dr.Read
dt.Rows.Add(New ListItem(dr("FullCCNum")))
Loop

dt.Rows.Add("Description")

DoWhile dr.Read
dt.Rows.Add(New ListItem(dr("CC_Descr")))
Loop


Hi, may be you can consider returning a string array can represent the result in a well formated way?

For instance:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
string[] words = prefixText.Split(new char[] { ';' });
string[] result = new string[16];
for (int i = 0; i < 16; i++)
{
result[i] = datarow["column1"] + "\t[ Use a tab to separate different columns ]" + datarow["column2"] ;
}
return result;
}


Would you mind translating to Visual Basic-- I have a translator, but it doesn't like that usage of datarow:

PublicSharedFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()
Dim wordsAsString() = prefixText.Split(NewChar() {";"c})
Dim resultAsString() =NewString(15) {}

For iAsInteger = 0To 15
result(i) = DataRow("column1") +"" & Chr(9) &"[ Use a tab to separate different columns ]" + DataRow("column2")
Next

Return result

EndFunction

A control with ID ImageButton5 could not be found for the trigger in UpdatePanel up1.

I have 20 ImageButtons on my page and UpdatePanel . In Update Panel Triggers i've added all this buttons

<asp:AsyncPostBackTriggerControlID="IB1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton2"/>

<asp:AsyncPostBackTriggerControlID="ImageButton3"/>

<asp:AsyncPostBackTriggerControlID="ImageButton4"/>

<asp:AsyncPostBackTriggerControlID="ImageButton5"/> Here I am Getting this Message

A control with ID 'ImageButton5' could not be found for the trigger in UpdatePanel 'up1'.

4 first Image Buttons update panel can find but after 5th no ..... What can be the problem ??

Please post your source code so we can see it in the context of the entire page.


Post some more code details, So it will be more helpful


<asp:UpdatePanelID="up1"UpdateMode="Conditional"runat="server"ChildrenAsTriggers="True">

<Triggers>

<asp:AsyncPostBackTriggerControlID="IB1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton1"/>

<asp:AsyncPostBackTriggerControlID="ImageButton2"/>

<asp:AsyncPostBackTriggerControlID="ImageButton3"/>

<asp:AsyncPostBackTriggerControlID="ImageButton4"/>

<asp:AsyncPostBackTriggerControlID="ImageButton5"/>

</Triggers>

<ContentTemplate>

This is Update Panel code :

and there are just 20 ImageButtons on form ... thats all code


Seeing the rest of the page would really help.


Hi,

Thank you for your post!

Where is yourImageButton5? Is it in anothernaming container?

You cann't set button that is in a different naming container with the updatepanle as a trigger. That is the answer.

If you really want it to be a trigger, this is the workaround:

Programmatically addingAsyncPostBackTrigger controls is not supported. Find out the control viafindcontrol method, then use theRegisterAsyncPostBackControl(Control) method of theScriptManager control to programmatically register a postback control, and then call theUpdate() method of theUpdatePanel when the control posts back.

If you have further questions,let me know!

Best Regards,


Thanks a lot for your reply ...

I am sorry for my dummy knowlege but what does it meananothernaming container ?

my button is on the same page in same <table> but in different <tr> , this could be a problem ?


Hi,

Thank you for your feedback!

Seehttp://msdn2.microsoft.com/en-us/library/system.web.ui.inamingcontainer.aspx.

INamingContainer Interface

Identifies a container control that creates a new ID namespace within aPage object's control hierarchy. This is a marker interface only.

Naming container is a container contorl which implemented the INamingContainer Interface, contorls in Naming container 2 have different ID namespace with contorls in Naming container 1, so ....

If you have further questions, let me know.

Best Regards,