Help with syntax

A

arlie

I am working with the asp.net blog posted at msdn by marco bellianso, msdn
october 2003.

The problem is that the javascript (ToggleDivState) to show and hide
comments does not work in browsers other than ie. So I have another
javascript that works across most browsers. The script I am using needs a
single quoted div

To test my script I inserted the following line where I have hardcoded the
div (div3).

<a href="javascript:ShowHide('div3');">show layer</a>

What I need is to add single quotes to the following code (div" &
Container.DataItem(MessageId") & ") . The full line is below.

<asp:HyperLink Runat="server" Visible='<%#
Container.DataItem("CommentsCount") > 0 %>'
NavigateUrl='<%# "javascript:ShowHide(div" & Container.DataItem("MessageID")
& ");" %>'>View</asp:HyperLink>


Everything I try gives a server tag is not well formed error.

Thanks
arlie
 
C

Craig Deelsnyder

arlie said:
<a href="javascript:ShowHide('div3');">show layer</a>

What I need is to add single quotes to the following code (div" &
Container.DataItem(MessageId") & ") . The full line is below.

<asp:HyperLink Runat="server" Visible='<%#
Container.DataItem("CommentsCount") > 0 %>'
NavigateUrl='<%# "javascript:ShowHide(div" & Container.DataItem("MessageID")
& ");" %>'>View</asp:HyperLink>


Everything I try gives a server tag is not well formed error.

Thanks
arlie
Create a function in your codebehind and then call it in the bind (watch
line wrapping)..in the codebehind

Function CreateJScriptCall(messageID as Object) as String
return "javascript:ShowHide('div" & Convert.ToString(messageID) & "');"
End Function

Then your tag above uses

NavigateUrl='<%# CreateJScriptCall(Container.DataItem("MessageID")) %>'
 
A

arlie

Thanks Craig,

Still have a problem.

I created the fuction in my default.aspx.vb file. Saved the file. Changed
up the line in the default.aspx. Rebuilt the solution. When I view it in
the browser I get Name 'CreateJScriptCall' is not declared. This is only my
second project in asp.net. Moving over from asp.

thanks,
arlie
 
C

Craig Deelsnyder

arlie said:
Thanks Craig,

Still have a problem.

I created the fuction in my default.aspx.vb file. Saved the file. Changed
up the line in the default.aspx. Rebuilt the solution. When I view it in
the browser I get Name 'CreateJScriptCall' is not declared. This is only my
second project in asp.net. Moving over from asp.

thanks,
arlie

Hmmm...that should work. Forgot to say the function must at least be
Protected as well. I think not specifying Protected Function makes it
ok, but you should pry specify Protected Function instead of Function
like I had in the code-behind.....are you sure the default.aspx.vb is
declared as the codebehind? Check the directives at the top of the
..aspx file and make sure they point at this class/file. Also, check for
typos in the tag in the .aspx....looks fine to me....
 
A

arlie

Craig,

My aplogies I had a typo. Plus we did not need to add Protected.

Another request for help?

The code posted at msdn also has the same problem when it comes to posting a
comment.

Here is the Javascript that shows the comment box when a user clicks on
'Post your own comments'

function ShowCommentBox(msgID)
{
// set the ParentMessageID hidden field with the ID of the
message being commented
document.forms[0].ParentMessageID.value = msgID;
// expand the CommentBox div
ShowCommentBox2();
}

function ShowCommentBox2()
{
// expand the CommentBox div
CommentBox.style.display = "";
// jump to the CommantBox, so that it becomes visible even if
the page
// is very long and the user is currently at the top of it
window.location.href = '#CommentBoxAnchor';

I wanted to use the same javascipt that I used before to showhide comments

function ShowHide(elementid){
if (document.getElementById(elementid).style.display == 'none'){
document.getElementById(elementid).style.display = '';
} else {
document.getElementById(elementid).style.display = 'none';
}
}


Here is the line in the default.aspx page:
- <a href='<%# "javascript:ShowCommentBox(" &
Container.DataItem("MessageID") & ");" %>'>
Post your own comment</a>

As you can see I have the same problem as before when I replace
ShowCommentBox with ShowHide and add a single quote to the line.

Why do they, msdn, post articles like this when they do not work across
multiple browsers? At least I'm learning. Just don't know enough yet to
solve problems like this.

thanks,
arlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top