473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Problems with ASP.Net 2.0 and JavaScript

OK,

Im working with a DataList in .Net 2.0, the code shows the list when
the query has executed. I have the page feature in its own div and
display:none so its not visible until the list shows. Ive written
javascript in ASP.Net to show the DIV. The code is as follows:
jScript = "<script LANGUAGE=""javascript"">" & vbNewLine
jScript = jScript & "function ToggleDiv(id){" & vbNewLine
jScript = jScript & "var elem = document.getElementById(id);" &
vbNewLine
jScript = jScript & "if (elem)" & vbNewLine
jScript = jScript & "{" & vbNewLine
jScript = jScript & " if (elem.style.display != 'block')" &
vbNewLine
jScript = jScript & " {" & vbNewLine
jScript = jScript & " elem.style.display = 'block';"
&vbNewLine
jScript = jScript & " elem.style.visibility = 'visible';"
& vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & " else" & vbNewLine
jScript = jScript & " {" & vbNewLine
jScript = jScript & " elem.style.display =
'none';" & vbNewLine
jScript = jScript & " elem.style.visibility =
'hidden';" & vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & "}" & vbNewLine
jScript = jScript & "ToggleDiv('Page_Div');" & vbNewLine
jScript = jScript & "</sc" & "ript>"
Response.Write(jScript)
I dont get any errors, but the javascript doesn't execute either.
Anyone have any ideas?

Jul 27 '06 #1
3 1531
<ri*****@psychocoder.netwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
I dont get any errors, but the javascript doesn't execute either.
Anyone have any ideas?
I'm not a VB.NET specialist, but what happens if you replace vbNewLine with
"\n"
Jul 27 '06 #2

I think you gotta register it with the page (or are you not showing that
part?)

here is a sample I had ... written in vb.net

its actually a part of a class, where the constructor has the Page ... so I
can reuse it.

that's what _currentPage is all about.
I'd get a basic thing working first.. ( just an alert or something?) before
dealing with the hidden div stuff.


Private Sub CreateTrimJS()

Dim sb As StringBuilder = New StringBuilder

sb.Append("<!-- " & vbCrLf)
sb.Append("function trim(str) {" & vbCrLf)

''http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20959311.ht
ml

''sb.Append("alert('got to trim function -->' + str);" &
vbCrLf)

sb.Append("var returnVal='';" & vbCrLf)

sb.Append("returnVal=str.replace(/^\s*|\s*$/g,"""");" &
vbCrLf)

''debug
''sb.Append("alert('str -->*' + str + '*\nreturnVal--*' +
returnVal + '*');" & vbCrLf)
sb.Append("return returnVal;" & vbCrLf)

''close the entire function
sb.Append("}" & vbCrLf)
sb.Append(vbCrLf & "// -->" & vbCrLf)


If (Not
_currentPage.IsStartupScriptRegistered("someunique valueHere")) Then
'prevents a "double register"

_currentPage.RegisterStartupScript("someuniquevalu eHere", sb.ToString)
End If

End Sub


<ri*****@psychocoder.netwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
OK,

Im working with a DataList in .Net 2.0, the code shows the list when
the query has executed. I have the page feature in its own div and
display:none so its not visible until the list shows. Ive written
javascript in ASP.Net to show the DIV. The code is as follows:
jScript = "<script LANGUAGE=""javascript"">" & vbNewLine
jScript = jScript & "function ToggleDiv(id){" & vbNewLine
jScript = jScript & "var elem = document.getElementById(id);" &
vbNewLine
jScript = jScript & "if (elem)" & vbNewLine
jScript = jScript & "{" & vbNewLine
jScript = jScript & " if (elem.style.display != 'block')" &
vbNewLine
jScript = jScript & " {" & vbNewLine
jScript = jScript & " elem.style.display = 'block';"
&vbNewLine
jScript = jScript & " elem.style.visibility = 'visible';"
& vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & " else" & vbNewLine
jScript = jScript & " {" & vbNewLine
jScript = jScript & " elem.style.display =
'none';" & vbNewLine
jScript = jScript & " elem.style.visibility =
'hidden';" & vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & "}" & vbNewLine
jScript = jScript & "ToggleDiv('Page_Div');" & vbNewLine
jScript = jScript & "</sc" & "ript>"
Response.Write(jScript)
I dont get any errors, but the javascript doesn't execute either.
Anyone have any ideas?

Jul 27 '06 #3
This works fine for me. However, It DOESN'T work if your div is AFTER
this block, it doesn't exist in the dom when you call the function with
the line:

ToggleDiv('Page_Div');

If your div is before this block, it works fine.

I advise putting the whole function in a .js file and including it into
your web page in a <scripttag between the <head.. </headsection.
That will make it easier to read/debug. I'd then put the
"ToggleDiv('Page_Div');" call in the onload event of the <bodytag.
That way, no matter where the DIV exists, IE will only call your toggle
function once the entire page is loaded into the DOM.

ri*****@psychocoder.net wrote:
OK,

Im working with a DataList in .Net 2.0, the code shows the list when
the query has executed. I have the page feature in its own div and
display:none so its not visible until the list shows. Ive written
javascript in ASP.Net to show the DIV. The code is as follows:
jScript = "<script LANGUAGE=""javascript"">" & vbNewLine
jScript = jScript & "function ToggleDiv(id){" & vbNewLine
jScript = jScript & "var elem = document.getElementById(id);" &
vbNewLine
jScript = jScript & "if (elem)" & vbNewLine
jScript = jScript & "{" & vbNewLine
jScript = jScript & " if (elem.style.display != 'block')" &
vbNewLine
jScript = jScript & " {" & vbNewLine
jScript = jScript & " elem.style.display = 'block';"
&vbNewLine
jScript = jScript & " elem.style.visibility = 'visible';"
& vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & " else" & vbNewLine
jScript = jScript & " {" & vbNewLine
jScript = jScript & " elem.style.display =
'none';" & vbNewLine
jScript = jScript & " elem.style.visibility =
'hidden';" & vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & " }" & vbNewLine
jScript = jScript & "}" & vbNewLine
jScript = jScript & "ToggleDiv('Page_Div');" & vbNewLine
jScript = jScript & "</sc" & "ript>"
Response.Write(jScript)
I dont get any errors, but the javascript doesn't execute either.
Anyone have any ideas?
Jul 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
3
by: Curious Angel | last post by:
Help? Spec Character Problems w/JAVASCRIPT TOOLTIP Hi, I'm experiencing bizarre problems with quote marks that previously displayed properly in a Javascript TOOLTIP I wrote a year ago . . . and...
0
by: Linda Antonsson | last post by:
Hi, I am trying to put together a CSS-based layout consisting of a header, a sidebar and a main content area. Page: http://www.westeros.org/ASoWS/ CSS:...
3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
55
by: drhowarddrfine | last post by:
I'm working on a web site that could use some control using js but am concerned about what problems I may have with potential users having their js turned off. Has anyone had any serious problems...
13
by: nick4soup | last post by:
General advice wanted: Some web sites (including two large companies in Australia) get themselves awfully confused if the user presses the BACK button in their browser (and possibly the forward...
2
by: Jeronimo Bertran | last post by:
A couple of questions I am having problems with converting my JavaScript to C#. I have the following code using JavaScript for the mouseover handler that works fine: <SCRIPT...
3
by: PCgeek | last post by:
sorry moved this over to javascript forum, didn't mean to post 2x! Hi guys, I'm trying to put the finishing touches on my website and could really use some help on this particular issue. My page...
11
by: vortex93 | last post by:
hello, i have IE 6 and all the things that need for java in Security Settings are Enable and i still have problems with java like: when i want to open a window that have javascript as link it's...
10
by: jodleren | last post by:
Hi I know, that there are a lot of people having problems with orkut.com, errors like "object expected" and named objects missing. When loading the site can generate some 10 errors, and still...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.