EditURL in a UserControl

Last post 12-27-2005 11:46 AM by exptrade2000. 13 replies.

Sort Posts:

  • EditURL in a UserControl

    07-29-2005, 8:59 AM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699
    If built a custom user control (like the sectionheadcontrol) that contains the EditURL function, the function will return -1 for the ModuleID.


    How do I call the EditURL("MyEditControl") in a custom user control that will return the moduleID of the current module instance?
    matchbx
  • Re: EditURL in a UserControl

    07-29-2005, 9:26 AM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699

    OK, I found something that works but would this be considered a best pratice.

    In my custom user control I created a public property called EditURLValue like so

    Private _EditURLValue As String

    Public Property EditURLValue() As String

    Get

    Return _EditURLValue

    End Get

    Set(ByVal Value As String)

    _EditURLValue = Value

    End Set

    End Property


    Then I created the custom user control on my main form like so

    <cus:MyControl  id="mcMyCustomControl"  runat="server" EditURLValue='<%# EditURL("SomeEditPage") %>'    ></cus:MyControl>


    Back at my custom user control (front end form this time)

    I created a Hyperlink control and used this for the NavigateURL Property

    NavigateURL='<% # EditURLValue() %>'


    Now the Hyperlink in the custom user control will return the module ID,  But is there a better way.....

    matchbx
  • Re: EditURL in a UserControl

    08-04-2005, 2:13 PM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699
    Did anyone ever get a chance to look at this?  

    I'm really interested in hearing from folks that have developed large modules and how they kept from having a single .ascx page with 1000 or more lines of html.
    matchbx
  • Re: EditURL in a UserControl

    08-04-2005, 4:55 PM
    • Participant
      1,340 point Participant
    • uzi
    • Member since 06-24-2002, 10:10 AM
    • Syracuse, NY
    • Posts 268
    Is your UserControl inherit from the PortalModuleBase? In my modules with many sub-controls, I just have to make sure they are Inheriting from the PortalModuleControl and not the UserControl object. This should give you a valid me.ModuleId along with all the other objects DNN creates.

    What I usually do, is create a class that inherits from the PortalModuleBase, and I'll use that in my custom modules. This way if the namespace changes again, I just have 1 file to update.
    Thanks,
    Oliver
  • Re: EditURL in a UserControl

    08-05-2005, 8:01 AM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699
    Thanks for the info.  I think this is the piece I was missing.  I should be able to give it a try today.
    matchbx
  • Re: EditURL in a UserControl

    08-05-2005, 9:47 AM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699
    OK.. the EditURL in the custom user control is still giving me -1 for a moduleid.  Heres what I have:

    User Control.ascx.vb

    Imports System
    Imports System.Web
    Imports System.Web.UI

    Namespace myns.DNN.Modules.MyCusModuleName

    Public MustInherit Class CustomUserControl
    Inherits Entities.Modules.PortalModuleBase
    ...
    ...
    ...
    End Class
    End
    Namespace


    UserControl.ascx

    <%@ Control Language="vb" AutoEventWireup="false" Codebehind="UserControl.ascx.vb" Inherits="myns.DNN.Modules.MyCusModuleName.CustomUserControl" %>

    <asp:hyperlink id="hypNavEdit" NavigateUrl='<%# EditURL("SomeEditPage") %>' runat="server" > Edit Part Summary</asp:hyperlink>



    MAINModuleControl.ascx

    <%@ Register TagPrefix="Custom" TagName="ctrl" Src="UserControl.ascx" %>

    <Custom:ctrl id="cusctrl1" runat="server"></Custom:ctrl>

    I then declared the cusctrl in the MainModuleControl.ascx.vb

    Protected WithEvents cusctrl1 As myns.DNN.Modules.MyCusModuleName.CustomUserControl



    The custom user control loads, but the ModuleID in the hyperlinks URL is -1 instead of the actual moduleID.
    What am I missing??


    P.S.  Both files are in the same directory.



    matchbx
  • Re: EditURL in a UserControl

    08-06-2005, 5:22 PM
    • Star
      7,685 point Star
    • vmasanas
    • Member since 09-17-2003, 2:48 AM
    • Banyoles, Girona (Spain)
    • Posts 1,550
    How about declaring a ModuleId property on the user control and passing the correct moduleid upon instantiating it?
    Think of it: you're building a general user control that need a param to work ok, so I suppose the param can be passed uh?

    - in your user control define a moduleid property
    - then when you add it to a dnn module use this:
    <Custom:ctrl id="cusctrl1" runat="server" ModuleId='<%=ModuleID%>'></Custom:ctrl>
  • Re: EditURL in a UserControl

    08-06-2005, 6:01 PM
    • Participant
      1,340 point Participant
    • uzi
    • Member since 06-24-2002, 10:10 AM
    • Syracuse, NY
    • Posts 268

    I recommend not using the Late Binding syntax (i.e.. <%= ModuleId %>) as that can reck some havoc on the module caching and the skinning engine from DNN.

    I would however recommend using either the Page_Load or Page_Init events to populate the usercontrol with cusctrl1.ModuleId = ModuleId. If you use the Page_Load event, make sure it's not inside a If IsPostBack = False Then line of code..

    Thanks,
    Oliver
  • Re: EditURL in a UserControl

    08-06-2005, 6:42 PM
    • Participant
      1,340 point Participant
    • uzi
    • Member since 06-24-2002, 10:10 AM
    • Syracuse, NY
    • Posts 268
    Actually, What you're missing is the ModuleConfiguration object, which seems to hold the ModuleId value.

    So, on Page_Init you'll need to do something like this...

    cusctrl1.ModuleConfiguration = Me.ModuleConfiguration

    If that usercontrol already inherits from the PortalModuleBase, that property will already exist. If you're using the plain jane UserControl base class, you'll need to add the ModuleConfiguration property which is of type ModuleInfo.

    I just looked at my modules which do this, and that's how I've gotten the ModuleId to be valid on sub-usercontrols.

    Thanks,
    Oliver
  • Re: EditURL in a UserControl

    08-06-2005, 7:26 PM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699

    uzi,  this sounds as though it will work.  I am using the PortalModuleBase so using this method I should be able to make it work.  I'll post back.

    matchbx
  • Re: EditURL in a UserControl

    08-08-2005, 6:48 AM
    • Member
      30 point Member
    • frankenpeggy
    • Member since 03-09-2004, 10:29 AM
    • Posts 6
    Setting the modulecontrol property for each sub-user control in the main page worked for me (problem here).
  • Re: EditURL in a UserControl

    08-08-2005, 7:42 AM
    • Contributor
      3,432 point Contributor
    • matchbx27
    • Member since 03-12-2003, 8:40 AM
    • Posts 699

    Yep worked for me too...

    matchbx
  • Re: EditURL in a UserControl

    09-01-2005, 10:39 AM
    • Member
      80 point Member
    • ace
    • Member since 06-24-2005, 7:13 PM
    • Northeast Ohio
    • Posts 16
    Yes, this is a great solution.
  • Re: EditURL in a UserControl

    12-27-2005, 11:46 AM
    • Contributor
      3,309 point Contributor
    • exptrade2000
    • Member since 03-03-2004, 5:01 AM
    • Allen, TX
    • Posts 710

    I would not recomend inherithing from PortalModuleBase for nested user controls. Convinience inheriting is a bad practice. What you need to do is expose a PortalModuleBase propoerty on a user control and then assign it in Page_Init. like this.

    ctlSomeNestedUserControl.PortalModuleBase = Ctype(me,PortalModuleBase)

    or if you do not need everything that is in portalmodulebase, you can expose on ModuleInfo property and do the same thing.

    You died at the very end of your life
Page 1 of 1 (14 items)