More problems With Controls

Discussion in 'ASP .Net Web Controls' started by poolguard, Dec 2, 2004.

  1. poolguard

    poolguard Guest

    I have posted this problem a few times before and gotten responses about not
    enough information about the Problem so this time I will give a lot of info.


    I am having a problem with some Web User Controls in a new web app I am
    developing.

    Here is the situation:

    I have a Base Page (Form.aspx), Form.aspx loads 2 web user controls
    Menu.ascx, Warn.ascx that never change and a web user control that is
    selected dynamically at runtime and contains the body of the page/form. On
    each of the body web user controls I have a bunch of server controls and a
    few functions on of the functions is for validating the page Val(). So when
    the page gets submitted back the Val() function gets called and if true goes
    onto the next part of code.

    If Val() = True Then
    GoNext("SelectOne")
    End If

    At that point the code works fine however what I need to do is when an image
    button is clicked on the Menu.ascx I need to Fire off Val() in the Body
    control. So something like this

    Private Sub IbnLogIn_Click(ByVal sender As System.Object, ByVal e As
    System.Web.UI.ImageClickEventArgs) Handles IbnLogIn.Click
    If Parent.Something.Somthing.Val() = True Then
    Parent.Something.Somthing.GoNext(“Marketingâ€)
    End Sub

    So my problem is I need to fire off a function of one control from another
    control.

    What I have tried:
    I have tried to as s session var to the application that would hold true and
    the one parameter for GoNext to run in the Page_Load Event like this

    If Session.Item("NeedVal") = True and Val() = True Then
    GoNext(Session.Item("GoNext"))
    End If

    The problem I have with this is I have to load the body web control before I
    load the menu.ascx control so by the time the click event for the image
    button on the menu.ascx has fired the page_load event on the body control is
    long over. If I put the menu control before the body control then the body
    state is not retained between postbacks.

    Is this possible or am I still confusing everyone by making no sense?

    Any ideas.

    Thanks
    Poolguard
     
    poolguard, Dec 2, 2004
    #1
    1. Advertising

  2. "poolguard" <> wrote in message
    news:...
    >I have posted this problem a few times before and gotten responses about
    >not
    > enough information about the Problem so this time I will give a lot of
    > info.
    >
    >
    > I am having a problem with some Web User Controls in a new web app I am
    > developing.
    >
    > Here is the situation:
    >
    > I have a Base Page (Form.aspx), Form.aspx loads 2 web user controls
    > Menu.ascx, Warn.ascx that never change


    If they never change, then why is Form.aspx loading them? Why aren't they
    just declared inside of Form.aspx?

    > and a web user control that is
    > selected dynamically at runtime and contains the body of the page/form. On
    > each of the body web user controls I have a bunch of server controls and a
    > few functions on of the functions is for validating the page Val(). So
    > when
    > the page gets submitted back the Val() function gets called


    Exactly where are you calling it from? Which event in which control?

    > and if true goes
    > onto the next part of code.
    >
    > If Val() = True Then
    > GoNext("SelectOne")
    > End If
    >
    > At that point the code works fine however what I need to do is when an
    > image
    > button is clicked on the Menu.ascx I need to Fire off Val() in the Body
    > control. So something like this
    >
    > Private Sub IbnLogIn_Click(ByVal sender As System.Object, ByVal e As
    > System.Web.UI.ImageClickEventArgs) Handles IbnLogIn.Click
    > If Parent.Something.Somthing.Val() = True Then
    > Parent.Something.Somthing.GoNext("Marketing")
    > End Sub


    I recommend that you use something like the Mediator pattern, with Form.aspx
    as the Mediator. In particular, let all controls communicate with Form.aspx,
    and let Form.aspx communicate with all controls. The controls should not
    communicate to each other.

    One example of this is that Menu.ascx should declare a public
    MenuItemClicked event, which Form.aspx should subscribe to. When Form.aspx
    sees this event, it should call Val on the Body control.

    > So my problem is I need to fire off a function of one control from another
    > control.
    >
    > What I have tried:
    > I have tried to as s session var to the application that would hold true
    > and
    > the one parameter for GoNext to run in the Page_Load Event like this
    >
    > If Session.Item("NeedVal") = True and Val() = True Then
    > GoNext(Session.Item("GoNext"))
    > End If
    >
    > The problem I have with this is I have to load the body web control before
    > I
    > load the menu.ascx control


    Why do you have to load the body first?

    > so by the time the click event for the image
    > button on the menu.ascx has fired the page_load event on the body control
    > is
    > long over. If I put the menu control before the body control then the
    > body
    > state is not retained between postbacks.


    Why not? It should be preserved.

    John Saunders
     
    John Saunders, Dec 2, 2004
    #2
    1. Advertising

  3. poolguard

    poolguard Guest

    Thank you that is the first Idea that anyone has had

    can i make a Custom event even thow it is not a real control (Just a ascx
    control) ans how. also how do i access the functions of the child
    control.ascx.
    this is how i load the controls

    Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)

    If Request.QueryString.Item("state") = "" Or
    Request.QueryString.Item("state") = "Login" Then
    MainForm.Controls.Add(LoadControl("Login.ascx"))
    ElseIf Request.QueryString.Item("state") = "SelectOne" Then
    MainForm.Controls.Add(LoadControl("SelectOption.ascx"))
    ElseIf Request.QueryString.Item("state") = "ClientType" Then
    MainForm.Controls.Add(LoadControl("ClientType.ascx"))
    ElseIf Request.QueryString.Item("state") = "ClientHistory" Then
    MainForm.Controls.Add(LoadControl("CliHistory.ascx"))
    ElseIf Request.QueryString.Item("state") = "areaoflaw" Then
    MainForm.Controls.Add(LoadControl("Areaoflaw.ascx"))
    ElseIf Request.QueryString.Item("state") = "Conflict" Then
    MainForm.Controls.Add(LoadControl("Conflict.ascx"))
    ElseIf Request.QueryString.Item("state") = "Marketing" Then
    MainForm.Controls.Add(LoadControl("Marketing.ascx"))
    ElseIf Request.QueryString.Item("state") = "Route" Then
    MainForm.Controls.Add(LoadControl("Route.ascx"))
    ElseIf Request.QueryString.Item("state") = "MailAdd" Then
    MainForm.Controls.Add(LoadControl("MailAdd.ascx"))
    ElseIf Request.QueryString.Item("state") = "BillAdd" Then
    MainForm.Controls.Add(LoadControl("BillAdd.ascx"))
    ElseIf Request.QueryString.Item("state") = "BillInfo" Then
    MainForm.Controls.Add(LoadControl("BillInfo.ascx"))
    End If
    MainForm.Controls.Add(LoadControl("Menu.ascx"))
    AddStaticText("<html>" & vbCr & "<head>" & vbCr & "<title>")
    Controls.Add(_title)
    AddStaticText("</title>" & vbCr & _
    "<meta name='vs_defaultClientScript' content='JavaScript'>" & vbCr & _
    "<meta name='vs_targetSchema'
    content='http://schemas.microsoft.com/intellisense/ie5'>" & vbCr & _
    "</head>" & vbCr & _
    "<body>" & vbCr)
    Me.Controls.Add(MainForm)
    AddStaticText(vbCr & "</body>" & vbCr & "</html>")
    End Sub

    if i add the menu.ascx first then the viewstate does not get retained

    Thank you very much


    "John Saunders" wrote:

    > "poolguard" <> wrote in message
    > news:...
    > >I have posted this problem a few times before and gotten responses about
    > >not
    > > enough information about the Problem so this time I will give a lot of
    > > info.
    > >
    > >
    > > I am having a problem with some Web User Controls in a new web app I am
    > > developing.
    > >
    > > Here is the situation:
    > >
    > > I have a Base Page (Form.aspx), Form.aspx loads 2 web user controls
    > > Menu.ascx, Warn.ascx that never change

    >
    > If they never change, then why is Form.aspx loading them? Why aren't they
    > just declared inside of Form.aspx?
    >
    > > and a web user control that is
    > > selected dynamically at runtime and contains the body of the page/form. On
    > > each of the body web user controls I have a bunch of server controls and a
    > > few functions on of the functions is for validating the page Val(). So
    > > when
    > > the page gets submitted back the Val() function gets called

    >
    > Exactly where are you calling it from? Which event in which control?
    >
    > > and if true goes
    > > onto the next part of code.
    > >
    > > If Val() = True Then
    > > GoNext("SelectOne")
    > > End If
    > >
    > > At that point the code works fine however what I need to do is when an
    > > image
    > > button is clicked on the Menu.ascx I need to Fire off Val() in the Body
    > > control. So something like this
    > >
    > > Private Sub IbnLogIn_Click(ByVal sender As System.Object, ByVal e As
    > > System.Web.UI.ImageClickEventArgs) Handles IbnLogIn.Click
    > > If Parent.Something.Somthing.Val() = True Then
    > > Parent.Something.Somthing.GoNext("Marketing")
    > > End Sub

    >
    > I recommend that you use something like the Mediator pattern, with Form.aspx
    > as the Mediator. In particular, let all controls communicate with Form.aspx,
    > and let Form.aspx communicate with all controls. The controls should not
    > communicate to each other.
    >
    > One example of this is that Menu.ascx should declare a public
    > MenuItemClicked event, which Form.aspx should subscribe to. When Form.aspx
    > sees this event, it should call Val on the Body control.
    >
    > > So my problem is I need to fire off a function of one control from another
    > > control.
    > >
    > > What I have tried:
    > > I have tried to as s session var to the application that would hold true
    > > and
    > > the one parameter for GoNext to run in the Page_Load Event like this
    > >
    > > If Session.Item("NeedVal") = True and Val() = True Then
    > > GoNext(Session.Item("GoNext"))
    > > End If
    > >
    > > The problem I have with this is I have to load the body web control before
    > > I
    > > load the menu.ascx control

    >
    > Why do you have to load the body first?
    >
    > > so by the time the click event for the image
    > > button on the menu.ascx has fired the page_load event on the body control
    > > is
    > > long over. If I put the menu control before the body control then the
    > > body
    > > state is not retained between postbacks.

    >
    > Why not? It should be preserved.
    >
    > John Saunders
    >
    >
    >
     
    poolguard, Dec 2, 2004
    #3
  4. "poolguard" <> wrote in message
    news:...
    > Thank you that is the first Idea that anyone has had
    >
    > can i make a Custom event even thow it is not a real control (Just a ascx
    > control) ans how. also how do i access the functions of the child
    > control.ascx.
    > this is how i load the controls
    >
    > Private Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
    >
    > If Request.QueryString.Item("state") = "" Or
    > Request.QueryString.Item("state") = "Login" Then
    > MainForm.Controls.Add(LoadControl("Login.ascx"))
    > ElseIf Request.QueryString.Item("state") = "SelectOne" Then
    > MainForm.Controls.Add(LoadControl("SelectOption.ascx"))
    > ElseIf Request.QueryString.Item("state") = "ClientType" Then
    > MainForm.Controls.Add(LoadControl("ClientType.ascx"))
    > ElseIf Request.QueryString.Item("state") = "ClientHistory" Then
    > MainForm.Controls.Add(LoadControl("CliHistory.ascx"))
    > ElseIf Request.QueryString.Item("state") = "areaoflaw" Then
    > MainForm.Controls.Add(LoadControl("Areaoflaw.ascx"))
    > ElseIf Request.QueryString.Item("state") = "Conflict" Then
    > MainForm.Controls.Add(LoadControl("Conflict.ascx"))
    > ElseIf Request.QueryString.Item("state") = "Marketing" Then
    > MainForm.Controls.Add(LoadControl("Marketing.ascx"))
    > ElseIf Request.QueryString.Item("state") = "Route" Then
    > MainForm.Controls.Add(LoadControl("Route.ascx"))
    > ElseIf Request.QueryString.Item("state") = "MailAdd" Then
    > MainForm.Controls.Add(LoadControl("MailAdd.ascx"))
    > ElseIf Request.QueryString.Item("state") = "BillAdd" Then
    > MainForm.Controls.Add(LoadControl("BillAdd.ascx"))
    > ElseIf Request.QueryString.Item("state") = "BillInfo" Then
    > MainForm.Controls.Add(LoadControl("BillInfo.ascx"))
    > End If
    > MainForm.Controls.Add(LoadControl("Menu.ascx"))
    > AddStaticText("<html>" & vbCr & "<head>" & vbCr & "<title>")
    > Controls.Add(_title)
    > AddStaticText("</title>" & vbCr & _
    > "<meta name='vs_defaultClientScript' content='JavaScript'>" & vbCr
    > & _
    > "<meta name='vs_targetSchema'
    > content='http://schemas.microsoft.com/intellisense/ie5'>" & vbCr & _
    > "</head>" & vbCr & _
    > "<body>" & vbCr)
    > Me.Controls.Add(MainForm)
    > AddStaticText(vbCr & "</body>" & vbCr & "</html>")
    > End Sub
    >
    > if i add the menu.ascx first then the viewstate does not get retained


    Ok, now I have a clue.

    Please stop creating the entire HTML content from this Page_Load! You're
    giving me a headache!

    Instead, try this on a "normal" .aspx page, and try loading the .ascx files
    into a Panel control (for instance). Do the same with the Menu.ascx, but
    load it first. Then see if your ViewState is preserved.

    Often, when wierd stuff happens while I'm doing wierd stuff, then when I
    stop doing wierd stuff, wierd stuff stops happening...

    John Saunders
     
    John Saunders, Dec 3, 2004
    #4
  5. "Leon Friesema" <leon@@frostbits.nl> wrote in message
    news:...
    > On Thu, 2 Dec 2004 21:31:09 -0500, "John Saunders" <johnwsaundersiii
    > at hotmail.com> wrote:
    >
    >>Often, when wierd stuff happens while I'm doing wierd stuff, then when I
    >>stop doing wierd stuff, wierd stuff stops happening...

    >
    > That's a philosopher :)


    No, just someone who constantly tries to do wierd stuff, and after a while
    remembers why not to do that... :-(


    John Saunders
     
    John Saunders, Dec 3, 2004
    #5
  6. poolguard

    poolguard Guest

    Thanks i will try that

    "John Saunders" wrote:

    > "Leon Friesema" <leon@@frostbits.nl> wrote in message
    > news:...
    > > On Thu, 2 Dec 2004 21:31:09 -0500, "John Saunders" <johnwsaundersiii
    > > at hotmail.com> wrote:
    > >
    > >>Often, when wierd stuff happens while I'm doing wierd stuff, then when I
    > >>stop doing wierd stuff, wierd stuff stops happening...

    > >
    > > That's a philosopher :)

    >
    > No, just someone who constantly tries to do wierd stuff, and after a while
    > remembers why not to do that... :-(
    >
    >
    > John Saunders
    >
    >
    >
     
    poolguard, Dec 3, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shess
    Replies:
    0
    Views:
    292
    shess
    Nov 24, 2003
  2. Michael
    Replies:
    4
    Views:
    427
    Matt Hammond
    Jun 26, 2006
  3. AW på ZRX

    Applet uses more and more CPU.

    AW på ZRX, Sep 11, 2006, in forum: Java
    Replies:
    3
    Views:
    374
    Tris Orendorff
    Sep 13, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    1,153
    Muhammad Naveed Yaseen
    Sep 5, 2007
  5. Robert Klemme

    With a Ruby Yell: more, more more!

    Robert Klemme, Sep 28, 2005, in forum: Ruby
    Replies:
    5
    Views:
    221
    Jeff Wood
    Sep 29, 2005
Loading...

Share This Page