Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > More problems With Controls

Reply
Thread Tools

More problems With Controls

 
 
poolguard
Guest
Posts: n/a
 
      12-02-2004
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

 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      12-02-2004
"poolguard" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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


 
Reply With Quote
 
 
 
 
poolguard
Guest
Posts: n/a
 
      12-02-2004
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.as cx"))
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >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
>
>
>

 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      12-03-2004
"poolguard" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.as cx"))
> 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


 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      12-03-2004
"Leon Friesema" <leon@@frostbits.nl> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
poolguard
Guest
Posts: n/a
 
      12-03-2004
Thanks i will try that

"John Saunders" wrote:

> "Leon Friesema" <leon@@frostbits.nl> wrote in message
> news:(E-Mail Removed)...
> > 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
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Controls.Count, Controls.IsSynchronized, and Controls.SyncRoot Nathan Sokalski ASP .Net 4 09-05-2007 03:27 AM
Kamaelia 0.4.0 RELEASED - Faster! More Tools! More Examples! More Docs! ;-) Michael Python 4 06-26-2006 08:00 AM
With a Ruby Yell: more, more more! Robert Klemme Ruby 5 09-29-2005 06:37 AM
DVD Verdict reviews: SYLVESTER AND THE MAGIC PEBBLE AND MORE MAGICAL TALES and more! DVD Verdict DVD Video 0 04-07-2005 08:10 AM
Re: With More Flash More Lumix: using an external flash unit with the FZ1 and other digicams Hans-Georg Michna Digital Photography 4 08-24-2003 06:05 PM



Advertisments