Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Pagelet (.ascx) problems


Message #1 by "Kevin James" <kjames45@h...> on Tue, 8 May 2001 13:29:53
I'm having a problem setting properties within a pagelet file. My calling 

script has the following:



<%@ Register TagPrefix="BI" TagName="LoginPage" 

src="Include/BI_LoginPage.ascx" %>



<BI:LoginPage id="loginPage" AddHeader="True" AddFooter="True" 

Framed="Yes" runat="server" />



And then the pagelet file has the following code:



<script language="VB" runat="server">



Private header As Boolean

Private footer As Boolean

Private frames As Boolean



Public Property AddHeader As Boolean

   Get

      If header then

         AddHeader = "True"

      Else

         AddHeader = "False"

      End if

   End Get



   Set

      If (String.Compare(AddHeader,"True",true) = 0) then

         header = true

      Else if (String.Compare(AddHeader,"Yes",true) = 0) then

         header = true

      Else

         header = false

      End if

   End Set

End Property



Public Property AddFooter As String

   Get

      If footer then

         AddFooter = "True"

      Else

         AddFooter = "False"

      End if

   End Get



   Set      

      If (String.Compare(AddFooter,"True",true) = 0) then

         footer = true

      Else if (String.Compare(AddFooter,"Yes",true) = 0) then

         footer = true

      Else

         footer = false

      End if

   End Set



End Property



Public Property Framed As String

   Get

      If frames then

         Framed = "True"

      Else

         Framed = "False"

      End if

   End Get



   Set

      If (String.Compare(Framed.ToString,"True",true) = 0) then

         frames = true

      Else if (String.Compare(Framed.ToString,"Yes",true) = 0) then

         frames = true

      Else

         frames = false

      End if

   End Set



End Property



</script>



The values being passed to the Set statements are ALWAYS "True" or "False" 

though, no matter what I put in the string calling it, and putting "True" 

does not necessarly mean that it will pass "True", it's just as likely, if 

not more likely, to pass "False" in that case.



Am I calling this wrong? Some change in VB that I've forgotten?!



Thanks in advance,

Kevin
Message #2 by "Samuel Engelman" <samuel_engelman@p...> on Tue, 8 May 2001 08:51:29 -0400
I'm not sure what your problem is exactly, but I did see one problem with

your code. If you think I am wrong I probably am since my .Net experience

is mostly with C#.



In the Property GETs you should return the value using



     Return <value>



Rather than



     Property = <value>



For Example:



Public Property AddHeader As Boolean

   Get

      If header then

         AddHeader = "True"

      Else

         AddHeader = "False"

      End if

   End Get



   Set

      If (String.Compare(AddHeader,"True",true) = 0) then

         header = true

      Else if (String.Compare(AddHeader,"Yes",true) = 0) then

         header = true

      Else

         header = false

      End if

   End Set

End Property



Should Be:



Public Property AddHeader As Boolean

   Get

      If header then

         Return "True"

      Else

         Return "False"

      End if

   End Get



   Set

      If (String.Compare(AddHeader,"True",true) = 0) then

         header = true

      Else if (String.Compare(AddHeader,"Yes",true) = 0) then

         header = true

      Else

         header = false

      End if

   End Set

End Property





Using the syntax that you are, you are assigning the value to the property

rather than returning it to the calling code. And since you are not

returning any value, it always shows up as false.





Please let me know if I am wrong.







|--------+--------------------------------->

|        |   "Kevin James"                 |

|        |   <kjames45@h...>        |

|        |                                 |

|        |                                 |

|        |   Tuesday May 8, 2001 09:29 AM  |

|        |   Please respond to "ASP+"      |

|        |                                 |

|--------+--------------------------------->

  >----------------------------------------------------------------------|

  |                                                                      |

  |      To:                                  "ASP+" <aspx@p...> |

  |      cc:                                                             |

  |      Subject: [aspx] Pagelet (.ascx) problems                        |

  >----------------------------------------------------------------------|









I'm having a problem setting properties within a pagelet file. My calling

script has the following:



<%@ Register TagPrefix="BI" TagName="LoginPage"

src="Include/BI_LoginPage.ascx" %>



<BI:LoginPage id="loginPage" AddHeader="True" AddFooter="True"

Framed="Yes" runat="server" />



And then the pagelet file has the following code:



<script language="VB" runat="server">



Private header As Boolean

Private footer As Boolean

Private frames As Boolean



Public Property AddHeader As Boolean

   Get

      If header then

         AddHeader = "True"

      Else

         AddHeader = "False"

      End if

   End Get



   Set

      If (String.Compare(AddHeader,"True",true) = 0) then

         header = true

      Else if (String.Compare(AddHeader,"Yes",true) = 0) then

         header = true

      Else

         header = false

      End if

   End Set

End Property



Public Property AddFooter As String

   Get

      If footer then

         AddFooter = "True"

      Else

         AddFooter = "False"

      End if

   End Get



   Set

      If (String.Compare(AddFooter,"True",true) = 0) then

         footer = true

      Else if (String.Compare(AddFooter,"Yes",true) = 0) then

         footer = true

      Else

         footer = false

      End if

   End Set



End Property



Public Property Framed As String

   Get

      If frames then

         Framed = "True"

      Else

         Framed = "False"

      End if

   End Get



   Set

      If (String.Compare(Framed.ToString,"True",true) = 0) then

         frames = true

      Else if (String.Compare(Framed.ToString,"Yes",true) = 0) then

         frames = true

      Else

         frames = false

      End if

   End Set



End Property



</script>



The values being passed to the Set statements are ALWAYS "True" or "False"

though, no matter what I put in the string calling it, and putting "True"

does not necessarly mean that it will pass "True", it's just as likely, if

not more likely, to pass "False" in that case.



Am I calling this wrong? Some change in VB that I've forgotten?!



Thanks in advance,

Kevin





Message #3 by "Kevin James" <kjames45@h...> on Tue, 8 May 2001 14:33:35
> I'm not sure what your problem is exactly, but I did see one problem with

> your code. If you think I am wrong I probably am since my .Net experience

> is mostly with C#.

> 

> In the Property GETs you should return the value using

> 

>      Return <value>

> 

> Rather than

> 

>      Property = <value>



Nope, there's no return in VB as far as I know. Unless that's changed in 

VB.NET. Normally you just assign the value to the property name (or 

function name if you're using a function) and it automatically gets 

returned.



Kevin
Message #4 by "Samuel Engelman" <samuel_engelman@p...> on Tue, 8 May 2001 09:53:37 -0400
Yes. i think this is one of the changes in .Net. I am familiar with VB 6

and I know what you mean. Try it and let me know





|--------+--------------------------------->

|        |   "Kevin James"                 |

|        |   <kjames45@h...>        |

|        |                                 |

|        |                                 |

|        |   Tuesday May 8, 2001 10:33 AM  |

|        |   Please respond to "ASP+"      |

|        |                                 |

|--------+--------------------------------->

  >----------------------------------------------------------------------|

  |                                                                      |

  |      To:                                  "ASP+" <aspx@p...> |

  |      cc:                                                             |

  |      Subject: [aspx] Re: Pagelet (.ascx) problems                    |

  >----------------------------------------------------------------------|









> I'm not sure what your problem is exactly, but I did see one problem with

> your code. If you think I am wrong I probably am since my .Net experience

> is mostly with C#.

>

> In the Property GETs you should return the value using

>

>      Return <value>

>

> Rather than

>

>      Property = <value>



Nope, there's no return in VB as far as I know. Unless that's changed in

VB.NET. Normally you just assign the value to the property name (or

function name if you're using a function) and it automatically gets

returned.



Kevin



Message #5 by "Kevin James" <kjames45@h...> on Wed, 9 May 2001 09:13:23
> Yes. i think this is one of the changes in .Net. I am familiar with VB 6

> and I know what you mean. Try it and let me know



It may be, but that's actually beside the point because I don't really 

need to GET the values. What I need to be able to do is SET them with the 

<BI:LoginPage > call. 



According to the Preview of ASP+ the code there should do that, but I 

guess the difference between the example in the book and my code is that 

I'm trying to set variables as opposed to values in a web control. 

However, I know the code is running, because if I put something like 

header = true after the if statement, the header will be set to true, but 

the value being passed to the pagelet is always "False" not whatever I put 

in the AddHeader="value" attribute of the <BI:LoginPage > call.
Message #6 by "Kevin James" <kjames45@h...> on Wed, 9 May 2001 10:18:53
Just to let others know since I finally figured this out:



When you're trying to set a property in VB using the code below, ASP.NET 

passes the value for the attribute in a variable called (surprisingly) 

Value. So what I should have been doing is the following:



Public Property AddHeader As String



   Get

      If header then

         Return "True"

      Else

         Return "False"

      End if

   End Get



   Set

      If (String.Compare(Value,"True",true) = 0) Then

         header = true

      Else if (String.Compare(Value,"Yes",true) = 0) Then

         header = true

      Else

         header = false

      End if

   End Set





End Property





> I'm having a problem setting properties within a pagelet file. My 

calling 

> script has the following:

> 

> <%@ Register TagPrefix="BI" TagName="LoginPage" 

> src="Include/BI_LoginPage.ascx" %>

> 

> <BI:LoginPage id="loginPage" AddHeader="True" AddFooter="True" 

> Framed="Yes" runat="server" />

> 

> And then the pagelet file has the following code:

> 

> <script language="VB" runat="server">

> 

> Private header As Boolean

> Private footer As Boolean

> Private frames As Boolean

> 

> Public Property AddHeader As Boolean

>    Get

>       If header then

>          AddHeader = "True"

>       Else

>          AddHeader = "False"

>       End if

>    End Get

> 

>    Set

>       If (String.Compare(AddHeader,"True",true) = 0) then

>          header = true

>       Else if (String.Compare(AddHeader,"Yes",true) = 0) then

>          header = true

>       Else

>          header = false

>       End if

>    End Set

> End Property

> 

> Public Property AddFooter As String

>    Get

>       If footer then

>          AddFooter = "True"

>       Else

>          AddFooter = "False"

>       End if

>    End Get

> 

>    Set      

>       If (String.Compare(AddFooter,"True",true) = 0) then

>          footer = true

>       Else if (String.Compare(AddFooter,"Yes",true) = 0) then

>          footer = true

>       Else

>          footer = false

>       End if

>    End Set

> 

> End Property

> 

> Public Property Framed As String

>    Get

>       If frames then

>          Framed = "True"

>       Else

>          Framed = "False"

>       End if

>    End Get

> 

>    Set

>       If (String.Compare(Framed.ToString,"True",true) = 0) then

>          frames = true

>       Else if (String.Compare(Framed.ToString,"Yes",true) = 0) then

>          frames = true

>       Else

>          frames = false

>       End if

>    End Set

> 

> End Property

> 

> </script>

> 

> The values being passed to the Set statements are ALWAYS "True" 

or "False" 

> though, no matter what I put in the string calling it, and 

putting "True" 

> does not necessarly mean that it will pass "True", it's just as likely, 

if 

> not more likely, to pass "False" in that case.

> 

> Am I calling this wrong? Some change in VB that I've forgotten?!

> 

> Thanks in advance,


  Return to Index