Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm working to implement global alerts by which they reside on the master page, and can be called from both content pages as well as user controls. I'm having an issue with the latter. The goal is to be able to call an alert from any page and have the masterpage UI display the alert regardless of postback state.

MasterPage.vb

#Region "UI Alerts"

Public Sub SetMessage(MessageTitle As String, MessageType As AlertTypes)
    Dim c As System.Web.HttpContext = System.Web.HttpContext.Current
    c.Session("_MessageTitle") = MessageTitle
    c.Session("_HasMessage") = True
    c.Session("_MessageType") = MessageType
    ShowAlert()
End Sub

Public Sub ShowAlert()
    Dim c As System.Web.HttpContext = System.Web.HttpContext.Current
    If Not String.IsNullOrEmpty(c.Session("_HasMessage")) AndAlso c.Session("_HasMessage") = True Then
        c.Session.Remove("_HasMessage")
        lblErrorMessage.Text = c.Session("_MessageTitle")
        RadAjaxPanel_alerts.ResponseScripts.Add(String.Format(" $('#ModalError').modal('show');"))
    End If
End Sub

#End Region

I've omitted the UI code as it is fairly trivial

Trigger alert from content page:

Helper.vb

Public MustInherit Class _AppUIPage
Inherits System.Web.UI.Page
Public _MasterPage As _AppMasterPage

Protected Sub Pre_render(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    _MasterPage = DirectCast(Me.Master, _AppMasterPage)
End Sub
End Class

Alert:

SetMessage("You Made A Mistake", Error)

From a user control:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim mp As _AppMasterPage = CType(Me.Page.Master, _AppMasterPage)
    mp.ShowMessage("Some Alert", Error)
End Sub

One of the use cases we have that induces more complexity. There are some pages that are not derived from the master page. Instead they are shown as 'modals' but are actually self contained pages displayed via a telerik RadWindow. Currently this requires javascript to pass data back to the parent page owning the window which then can display a message

share|improve this question
    
so you can't get the UserControls to call the alert the way you want them too? –  Malachi 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.