More problems With Controls

P

poolguard

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
 
J

John Saunders

poolguard said:
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
 
P

poolguard

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
 
J

John Saunders

poolguard said:
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
 
J

John Saunders

Leon Friesema said:
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
 
P

poolguard

Thanks i will try that

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


John Saunders
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top