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
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
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
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
If this is the tag in your aspx page ...
... and the property is called KeyphraseTextAssignment then all you should need to do is set the property inside this tag.<navito:merchantsfromfilename id="merchantsfromfilename" runat="server" />
So, assuming I haven't misunderstood what you are trying to do, your tag becomes
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:<navito:merchantsfromfilename id="merchantsfromfilename" runat="server" KeyphraseTextAssignment="mobile phones" />
then delete the get code.Code:Public WriteOnly Property KeyphraseTextAssignment() As String
Prezzybox.com home of the gift wizard
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.Originally Posted by accelerator
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
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks