Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Determining which module caused a postbackDetermining which module caused a postback
Previous
 
Next
New Post
5/14/2009 8:05 AM
 

I have two modules loaded onto a page. I have a Page.IsPostback condition that applies only to Module #1. if a Postback is fired from Module#2 then I do not want the  Page.IsPostback condition to apply. I need to add a ModuleID filter to the condition, but for this to work I need to be able to identify the module that caused the Postback. I cannot work out where I get this info from!

 
New Post
5/14/2009 8:42 AM
 

Is there any specific location in your module#2 where PageIsPostBack like any button or Dropdown or there are so many control to cause this

is you have specific button or control which cause your module PostBack than use DataCache class of DNN to store particular detail of module while PostBack Module and check this value at the other end.

thanks

 
New Post
5/14/2009 10:22 AM
 

It is normal ASP.Net behavior for all ascx controls on a page to go through their life cycle whenever any control (in any module or skin object, etc.) on the page causes a postback. Generally, it sould be sufficient for your module control to check for Page.IsPostback and handle accordingly. However, I can see a use case when you would need to identify the module which actually caused the postback. Here is some code which returns the ModuleId of the module causing the postback or a -1 if the postback was not caused by a DNN module. I have not tested it extensively but it should get you started:

Public Function GetPostBackModuleId() As Integer
   Dim ctrlId As String
   Dim mid As Integer = -1
   Dim sc As ScriptManager = ScriptManager.GetCurrent(Page)
   If sc IsNot Nothing AndAlso sc.IsInAsyncPostBack Then
        ctrlId = sc.AsyncPostBackSourceElementID
   Else
        ctrlId = Page.Request.Params.Get("__EVENT_TARGET")
        If String.IsNullOrEmpty(ctrlId) Then
             For Each id As String In Page.Request.form
                  Dim ctl As Control = Page.FindControl(id)
                  If ctl IsNot Nothing AndAlso TypeOf ctl Is System.Web.UI.WebControls.Button Then
                       ctrlId = id
                       Exit For
                  End If
             Next
        End If
    End If
    If Not String.IsNullOrEmpty(ctrlId) Then
        Dim m As RegularExpressions.Match
        m = Regex.Match(ctrlId, "\$ctr(\d+)\$")
        If m.Success Then
               mid = Convert.ToInt32(m.Groups(1).Value)
        End If
    End If
    Return mid
End Function

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
5/14/2009 10:49 AM
 

Thanks a lot, I'll try this

 
New Post
12/9/2010 4:34 AM
 
William,
in case anyone needs this, I just tested it on DNN 5.6: I had only to correct one line in this function:

ctrlId = Page.Request.Params.Get("__EVENT_TARGET")

to become

ctrlId = Page.Request.Params.Get("__EVENTTARGET")

Maybe this is related with the asp.net version in use? Anyway the function works with this modification.
Thank you for sharing!

al.

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Determining which module caused a postbackDetermining which module caused a postback


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out