Tuesday, March 13, 2012

Simple function not returning a value - pulling my hair out...

Hello,

This is driving me nuts, this is a simple function in my HTML that is simply not returning a value, what am I doing wrong?

Here is the call to the function in my HTML :

<html>
<head>
<title><% GetTitle () %></title
And here is the actual function between the script tags in the code behind :

Function GetTitle () As String

Return "Hello"

End Function

Any idea why this is not returning a value? I have been working on this for over an hour, and I cannot get the value "Hello" to appear in the HTML source after the page is run - any ideas?

Thanks,

DanPlease change the code to <title><%# GetTitle () %></title> and ensure that you are calling DataBind()

Hope that helps
Kashif
Ah...DataBind()

Ok, sorry for the dumb question, where should the DataBind() be? At the end of the Function?
Call it in Page_Load().

Hope that helps
Kashif
Ok, I'll call it in page load, but the problem is, I am not using a server control to bind to. This is just a value I want returned in my HTML - it is not going onto a label or anything. I'm just a beginner, sorry if it is a simple answer -

Can you give me an example of using the databind in this situation that I outlined above?

Thanks,

Dan
The following will work

 <html>
<head>
<title><%# GetTitle () %></title>
in code
Function GetTitle () As String
Return "Hello"
End Function
Sub Page_Load()
DataBind()
End Sub
Hope that helps
Kashif
Databinding is one solution, you can also do the following:

<title><% =GetTitle() %></title>

0 comments:

Post a Comment