CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > microsoft_downloads.css_friendly_control_adapters Tags:
Item Type: NewsGroup Date Entered: 11/2/2006 8:03:01 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 9 Views: 65 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
10 Items, 1 Pages 1 |< << Go >> >|
Guitarguy5
Asp.Net User
Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page11/2/2006 8:03:01 PM

0/0

Hello all - my first post here...

 I have a custom Navigation User Control which contains a TreeView inside of it.  I have placed this UserControl on my MasterPage.  All of my other pages will base their design on this Master Page - so the Navigation should show on each page.  The Navigation's TreeView points to a web.sitemap file. 

Everything works except that I cannot access the OnSelectedNodeChanged Event. 

Inside my userControl I have set the following attributes:

OnSelectedNodeChanged="OnClick"

OnAdaptedSelectedNodeChanged="OnClick"

I have also created a public OnClick event, and tried placing it in various locations - but none of them seem to work. 

I tried putting the Public OnClick event in the UserControl.ascx.cs file,

Also tried putting it in the MasterPage's code file -  MasterPage.cs,

None of these work - the SelectedNodeChanged event doesn't seem to get handled.

 Is this because the TreeView is nested inside a user control?

I need to handle this SelectedNodeChanged event.

 

Thanks

 

Russ Helfand
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page11/4/2006 1:42:42 PM

0/0

Hi Guitar Guy,

It sounds like you are doing the right things.  You've made the event handler public, not protected.  And you've assigned OnAdaptedSelectedNodeChanged rather than simply OnSelectedNodeChanged.  Putting the handler in the user control's code behind (usercontrol.acsx.cs) is the right thing.  I would have expected that to work.  Since it didn't we need to dig a bit deeper.

Are you willing to help with the debugging?  If so, here's what I recommend you do.

Use Visual Studio or VWD to run your web site in debug mode.  That means opening your web site in VWD or VS and hitting F5.  Put a break point at the first executable line within the method called RaisePostBackEvent in TreeViewAdapter.cs (or vb, depending on what language you've chosen to use).  Now try clicking on one of the tree nodes to cause the page to postback.  Do you break in RaisePostBackEvent?  If so, start walking through the execution of the code by hitting F10 again and again (slowly) and watching the logic flow.  Notice that RaisePostBackEvent has a call to Extender.RaiseAdaptedEvent for the SelectedNodeChanged event.  I'm guessing you are not going to reach that call because you said that your event handler doesn't get hit. However, it may be that you are actually hitting the call to Extender.RaiseAdaptedEvent.  If so, then you need to step INTO it by pressing F11 when you reach that line.

I took a look at the code for RaiseAdaptedEvent and it does look like there may be a problem in there in cases where the tree is in a user control rather than a page.  You'll see what I mean if you look at that method.  It looks at the tree's immediate parent and then it looks at the page to see if it can find the event handler function.  You're situation may be one where neither heuristic is good enough.  If that's the case, let me know and we'll work together to see if there is a simple way to enhance RaiseAdaptedEvent so it works properly in your case, too.

I look foward to hearing back from you.  Good luck.  We'll figure this out.


Russ Helfand
Groovybits.com
Guitarguy5
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page11/8/2006 6:42:56 AM

0/0

Hi Russ,

 Thanks for your reponse.  I realized that I made a typo in my code!  So in fact, I can set an OnClick event both in the code file for my user control AND my code behind file for my aspx page and both will get called.  Sorry about that and thanks for your help.

 

hgrewa
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page12/25/2006 2:27:24 AM

0/0

Thanks Russ for the tip. I had the similar problem. The selected nodechanged event is not raised if TreeView is in an updatepanel (using it with Ajax RC) and both of them are in the user control. So

For TreeView, 

.Parent is the System.Web.UI.Control

.Parent.Parnet is the updatepanel

.Parent.Parent.Parent is the user control, where the method lies.

WIth this, the following code in the RaiseAdaptedEvent method fails to invoke the SelectedNodeChanged event.

string delegateName = AdaptedControl.Attributes[attr];

 

//Original control code.

Control methodOwner = AdaptedControl.Parent;  

MethodInfo method = methodOwner.GetType().GetMethod(delegateName);

if (method == null)

{

methodOwner = AdaptedControl.Page;

method = methodOwner.GetType().GetMethod(delegateName);

}

 

if (method != null)

{

object[] args = new object[2];

args[0] = AdaptedControl;

args[1] = e;

method.Invoke(methodOwner, args);

}

}

 

I had to modify it for my case to get it worked. Thanks for your help. It sure saved me a lot of time.

Harpreet.


Grewal
http://www.mycoolaids.com/
Russ Helfand
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page12/25/2006 3:56:21 PM

0/0

Thanks for the feedback, Harpreet.  I agree.  I think there's a flaw in the code I wrote originally for RaiseAdaptedEvent.  What do you think about something that walks up the parent-list looking for the event delegate method like this?

        public void RaiseAdaptedEvent(string eventName, EventArgs e)
        {
            string attr = "OnAdapted" + eventName;
            if ((AdaptedControl != null) && (!String.IsNullOrEmpty(AdaptedControl.Attributes[attr])))
            {
                string delegateName = AdaptedControl.Attributes[attr];
                MethodInfo method = null;
                Control methodOwner = AdaptedControl.Parent;
                while ((method == null) && (methodOwner != null))
                {
                    method = methodOwner.GetType().GetMethod(delegateName);
                    methodOwner = methodOwner.Parent;
                }
                if (method == null)
                {
                    methodOwner = AdaptedControl.Page;
                    method = methodOwner.GetType().GetMethod(delegateName);
                }
               
                if (method != null)
                {
                    object[] args = new object[2];
                    args[0] = AdaptedControl;
                    args[1] = e;
                    method.Invoke(methodOwner, args);
                }
            }
        }

I've not yet tested this but it seems like it would a pretty save/simple change to the code that would work in more case.  If you happen to try this (or if any readers happen to try this) please post the results: did it work to fix cases where events weren't being fired properly for adapted controls within user controls?


Russ Helfand
Groovybits.com
hgrewa
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page12/25/2006 5:01:31 PM

0/0

Couple of things, I think there is bug in the code; In the while loop

                while ((method == null) && (methodOwner != null))
                {
                    method = methodOwner.GetType().GetMethod(delegateName);
                    methodOwner = methodOwner.Parent;
                }

if method has been found, mothodowner should not be changed as it is needed to invoke the event. so it should be

                while ((method == null) && (methodOwner != null))
                {
                    method = methodOwner.GetType().GetMethod(delegateName);

                    if(method != null)

                      methodOwner = methodOwner.Parent;
                }

In addition to this, you dont need

                if (method == null)
                {
                    methodOwner = AdaptedControl.Page;
                    method = methodOwner.GetType().GetMethod(delegateName);
                }
as, while going through all the partents, you will reach to the Page ultimately, i.e evantually, methodowner.parent will be equal to Page.

Here is what I have used in my code. I have tested it for my needs and it is working fine. Please let me know there is still a bug for some other scnario that i have not been tested against.

Russ, on a different subject, I have also found additional bugs, one of them is described at setting ShowCheckBox = true & node hyperlink disappears??  and other is with the css, In my tree view, I have added a background color to the selected nodes in the css by setting

.PrettyTree

div.AspNet-TreeView .AspNet-TreeView-Selected a

color: #ECED15 !important;

background-color: #165EA9 !important;

padding: 3px !important; }

in the TreeViewExample css, the problem I am having is that , if the selected node has some childrens then the same background is also applied to all the children in the selected node ??? , ( used on IE 7). Any help ??


Grewal
http://www.mycoolaids.com/
hgrewa
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page12/25/2006 5:03:45 PM

0/0

Oops, I forgot to put the modifed code that I am using, it is

while (null == method)

{

method = methodOwner.GetType().GetMethod(delegateName);

if (null == method)

{

methodOwner = methodOwner.Parent;

if(null == methodOwner)

throw new Exception("Error! in control adapters!");

}

}


Grewal
http://www.mycoolaids.com/
DementedDevil
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page1/15/2007 8:24:47 AM

0/0

Hi there!

I'm also having trouble with the TreeView adapter however looking at the recursion method above I have modified this loop into the following (appologies - this is in VB because I'm currently being forced to target DotNetNuke at gunpoint)

Dim methodOwner As Control = AdaptedControl.Parent

Dim method As MethodInfo = Nothing

While (IsNothing(method)) And (Not IsNothing(methodOwner))

     method = methodOwner.GetType().GetMethod(delegateName)

     If (IsNothing(method)) Then

          methodOwner = methodOwner.Parent

     End If

End While

 I removed the exception to ensure that a missing handler does not throw an exception - this allows code to be commented out for debugging without the adapter code getting upset!

Smile


Adrian L
aka Demented Devil
jkey
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page5/12/2007 5:08:32 PM

0/0

Just to clarify:

In the WebControlAdapterExtender.vb file, there is an error affecting treeview (using css adapters) when placed in user control.

The problem is that the SelectedNodeChanged event will not fire, as the extender will be looking for the event on the page and not in the user control.

Therefore, if the method is not firing, change this:

 

        Public Sub RaiseAdaptedEvent(ByVal eventName As String, ByVal e As EventArgs)
            Dim attr As String = "OnAdapted" + eventName
            If ((Not IsNothing(AdaptedControl)) AndAlso _
                (Not String.IsNullOrEmpty(AdaptedControl.Attributes(attr)))) Then
                Dim delegateName As String = AdaptedControl.Attributes(attr)
                Dim methodOwner As Control = AdaptedControl.Parent
                Dim method As MethodInfo = methodOwner.GetType().GetMethod(delegateName)
                If (IsNothing(method)) Then
                    methodOwner = AdaptedControl.Page
                    method = methodOwner.GetType().GetMethod(delegateName)
                End If
                If (Not IsNothing(method)) Then
                    Dim args() As Object = New Object(1) {}
                    args(0) = AdaptedControl
                    args(1) = e
                    method.Invoke(methodOwner, args)
                End If
            End If
        End Sub
 

 

with this:

        Public Sub RaiseAdaptedEvent(ByVal eventName As String, ByVal e As EventArgs)
            Dim attr As String = "OnAdapted" + eventName
            If ((Not IsNothing(AdaptedControl)) AndAlso _
                (Not String.IsNullOrEmpty(AdaptedControl.Attributes(attr)))) Then                
                Dim delegateName As String = AdaptedControl.Attributes(attr)
                Dim methodOwner As Control = AdaptedControl.Parent
                Dim method As MethodInfo = methodOwner.GetType().GetMethod(delegateName)
                While IsNothing(method)
                    method = methodOwner.GetType().GetMethod(delegateName)
                    If IsNothing(method) Then
                        methodOwner = methodOwner.Parent
                        If IsNothing(methodOwner) Then
                            Throw New Exception("Error! in control adapters!")
                        End If
                    End If
                End While

                If (Not IsNothing(method)) Then
                    Dim args() As Object = New Object(1) {}
                    args(0) = AdaptedControl
                    args(1) = e
                    method.Invoke(methodOwner, args)
                End If
            End If
        End Sub
 
chrisstead
Asp.Net User
Re: Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page5/23/2007 2:59:37 PM

0/0

I'm using a Control that derives from TreeView, so the RaiseAdaptedEvent actual need to start its search for the event handler in the current control, not the parent control.

A complete version of the modified C# therefore looks like this:

public void RaiseAdaptedEvent(string eventName, EventArgs e)
{
    string attr = "OnAdapted" + eventName;
    if ((AdaptedControl != null) && (!String.IsNullOrEmpty(AdaptedControl.Attributes[attr])))
    {
        string delegateName = AdaptedControl.Attributes[attr];
        Control methodOwner = AdaptedControl;
        MethodInfo method = null;               

        while (method == null)
        {
            method = methodOwner.GetType().GetMethod(delegateName);
            if (method == null)
            {
                methodOwner = methodOwner.Parent;
                if (methodOwner == null)
                {
                    throw new Exception("Error! in control adapters!");
                }
            }
        }

        if (method != null)
        {
            object[] args = new object[2];
            args[0] = AdaptedControl;
            args[1] = e;
            method.Invoke(methodOwner, args);
        }
    }
}
 

 

10 Items, 1 Pages 1 |< << Go >> >|


Free Download:


Web:
Can't Get OnAdaptedSelectedNodeChanged to work with UserControl ... Can't Get OnAdaptedSelectedNodeChanged to work with UserControl and Master Page. Last post 05-23-2007 10:59 AM by chrisstead. 9 replies. ...
Treeview on MasterPage - OnAdaptedSelectedNodeChanged doesn't fire ... Treeview on MasterPage - OnAdaptedSelectedNodeChanged doesn't fire .... If you post again here I can continue to work with you on this. ...
Debug - ng.asp-net-forum.dotnetnuke-custom_modules - error problem ... can't get onadaptedselectednodechanged to work with usercontrol and master page · sql injection, quick question · how can i add another language ...
clarification on web.config inheritance - ng.asp-net-forum ... HtmlEditorProvider inherit from Control, UserControl or WebControl? ... treeview on masterpage - onadaptedselectednodechanged doesn't fire ...




Search This Site:










error 1335 - corrupt cab file

cast error

fxcop used on 3.0?

is this a standard forms authentication feature?

generate email in vb.net

the request failed with http status 401: unauthorized - ssrs web service

help me create vertical menu with image?

treeview does not work on production machine

background image

what is the difference between html controls and web controls?

single blog posts not showing up

problem in the documentation

replacement for application test center ????

format date

problems with running on another machine

dnn 3.0, xhtml strict, tableless design & xhtmlwebcontrols...

referencing a login control

collectioneditor can't use with composite control?

which is the purpose of the registerstartupscript type parameter?

please help! selection menus lost css formatting

remove module title line

the portal source file not working 100%, how to complete manually?

second disk reference

dnn 3.0.12 - gallery module failure file not found

"exclude from project" but need file visible

tie invision board into aspx site

core forum in dotnetnuke

required field validator - what am i doing wrong?

granularized document sharing

customizing propertygrideditorpart control

 
All Times Are GMT