Results 1 to 6 of 6

 

Thread: Help! Setting property value in vb.net user control

  1. #1
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,034
    Thanks
    54
    Thanked 183 Times in 164 Posts


    Hi All

    If there are any vb.net coders here I could really use some help on what should be something simple but is currently driving me crazy.


    I have a .ascx User Control which I am incorporating into a .aspx page.

    In the .ascx user control file, I have an SQL statement, where I want to make use of a variable called KeyphraseText. It looks like this:


    <%

    .....

    Dim Sql As String = "SELECT ..... WHERE KeyphraseText LIKE '" & KeyphraseText & "' AND ...... ;"

    .....

    %>

    All I am trying to achieve is to set this variable from a line in my .aspx file. Sounds easy right? Well, I seem to be struggling. So far, I have been advised that the best way to achieve this is to add a vb.net property to the .ascx file, which I have done as follows:

    <script runat=server>


    Public KeyphraseText As String

    Public Property KeyphraseTextAssignment() As String


    Get

    Return KeyphraseText

    End Get


    Set(ByVal Value As String)

    KeyphraseText = Value

    End Set


    End Property


    </script>


    I think the syntax for my property statement is correct, so all I need to do now is set the property value from my .aspx file. FYI the id of the user control is merchantsfromfilename, and I have the following user control statement in my .aspx file:

    <navito:merchantsfromfilename id="merchantsfromfilename" runat="server" />

    The .aspx file does actually make use of a code behind page, so into that I have added my attempted assignment of the property in my user control as follows:

    merchantsfromfilename.KeyphraseTextAssignment = "mobile phones"

    Currently this line is causing the compiler error:

    Compiler Error Message: BC30188: Declaration expected.


    Can people please come to the assistance of a very frustrated coder. Bearing in mind my simple objective, can anyone shed any light on this problem?



    Thanks

    Accelerator

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Cheshire
    Posts
    263
    Thanks
    0
    Thanked 1 Time in 1 Post
    You shouldn't have <% or %> tags appearing in any of your .NET code at all - these tags apply to "old" ASP scripts.

    Can you give more of an idea of what you are trying to achieve, I may be able to offer some more help !

    Jon

  3. #3
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,034
    Thanks
    54
    Thanked 183 Times in 164 Posts
    Jon

    The fundamental thing that I am trying to achieve is to use vb.net to assign a variable in a .aspx page (or it's code behind page), that can then be recognised by a .ascx user control being incorporated on that .aspx page.

    So far I have tried declaring a Public variable in the .aspx page, but then I get a declaration required from the .ascx user control.

    Now I'm trying to add a property statement to the .ascx user control (which I think I have right) and add property assignment code to the .aspx page (which I'm still not sure of).

    Any thoughts?

    Thanks

    Accelerator

  4. #4
    Registered User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If this is the tag in your aspx page ...
    <navito:merchantsfromfilename id="merchantsfromfilename" runat="server" />
    ... and the property is called KeyphraseTextAssignment then all you should need to do is set the property inside this tag.

    So, assuming I haven't misunderstood what you are trying to do, your tag becomes

    Code:
    <navito:merchantsfromfilename id="merchantsfromfilename" runat="server" KeyphraseTextAssignment="mobile phones" />
    Incidently if you don't need to read the value of KeyphraseTextAssignment from the control I'd suggest changing the public property to WriteOnly.

    Code:
    Public WriteOnly Property KeyphraseTextAssignment() As String
    then delete the get code.
    Prezzybox.com home of the gift wizard

  5. #5
    Registered User

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by accelerator
    The fundamental thing that I am trying to achieve is to use vb.net to assign a variable in a .aspx page (or it's code behind page), that can then be recognised by a .ascx user control being incorporated on that .aspx page.
    I'm not sure if my earlier post fits the bill for you. My earlier post works if you know when the page is being designed what the value of KeyphraseTextAssignment will be.

    When you say assign a variable do you mean that you want to set the value at runtime? If so there are a couple of ways of doing that. I'd favour adding a placeholder into the aspx page, create the usercontrol in your code file set its property then add the control to the placeholder. It sounds more complicated that it is, if you want to do that let me know and I'll post some code.
    Prezzybox.com home of the gift wizard

  6. #6
    accelerator's Avatar
    Online shopping rocks!

    Status
    Offline
    Join Date
    Nov 2004
    Location
    England
    Posts
    3,034
    Thanks
    54
    Thanked 183 Times in 164 Posts
    Monkeyboy

    A big thank you, I had to make the property assignment within the tag, as you had suggested. Your help was much appreciated.

    All the best

    Accelerator



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. mysql user area
    By chrissy in forum Affiliate Marketing Lounge
    Replies: 1
    Last Post: 16-01-06, 04:11 PM
  2. New Affiliate Control Area
    By paidonresults in forum Paid On Results
    Replies: 1
    Last Post: 29-08-05, 07:00 PM
  3. Improved Affiliate Control Area
    By paidonresults in forum Paid On Results
    Replies: 6
    Last Post: 29-10-04, 09:36 PM
  4. New Merchant - The Property Investor Show
    By rufus in forum Affiliate Future
    Replies: 0
    Last Post: 31-08-04, 02:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2