.style.display = "None" won't stick

S

Sue

Help! I have an asp table with an embedded table. The asp
tablerow that contains this table has a static ID assigned
of "FilterRow2" (see snippets of code below). When I click
on the button to set the tablerow style property
to "None", the row (And embedded table) briefly disappear,
but then bounce right back into sight.

Any ideas on why it's doing this and how to make the
style.display = "None" stick?

tia,
Sue

control declared in .aspx page:

<asp:TableRow ID="FilterRow2" Runat="server">
<asp:TableCell Runat="server"
columnspan="6">

I have a client-side VBScript sub that sets the
DHTML "display" property of this FilterRow2 to "None"
or "InLine" triggered by a click on ASP Buttons.
These scripts are added to the project using
RegisterClientScriptBlock (see snip of the .aspx code-
behind below):

Me.ClientScriptString = "<script language=VBScript>" &
vbCrLf _
& " sub HideFilters()" & vbCrLf _
& " document.all(" & Chr(34) & Me.FilterRow2.ClientID & Chr
(34) & ").style.display = " & Chr(34) & "None" & Chr(34) &
vbCrLf _
& " end sub " & vbCrLf & "<" _
& "/" _
& "script>"

If (Not Page.IsClientScriptBlockRegistered("HideFilters"))
Then
Page.RegisterClientScriptBlock("HideFilters",
ClientScriptString)
End If

Here's the source code for the generated .ASPX page in an
IE browser:

<script language=VBScript>
sub HideFilters()
document.all("_ctl2_FilterRow2").style.display
= "None"
end sub
</script>

Here's the TableRow object in the source code in IE:

<tr id="_ctl2_FilterRow2">
 
J

Jacob Yang [MSFT]

Hi Sue,

I am interested in this issue and researching on it now. I will update you
as soon as possible.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jacob Yang [MSFT]

Hi Sue,

Please let me know how the client-side vbscript was called. Is there a
postback to the server following the call to that vbscript? If it is the
case (I mean there is a postback after the call to the script), the display
style property will be reset by the server-side rendering.

Please let me know more detailed on your code. I certainly appreciate your
time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Sue

Please let me know how the client-side vbscript was
called. Is there a
postback to the server following the call to that
vbscript? If it is the

There *shouldn't* be a post-back - that's what I'm trying
to avoid,
but maybe there's an implicit one I'm not aware of?
How could I test for this? thanks for help! Sue

' button declarations
Protected WithEvents FilterShowFiltersButton As New Button
Protected WithEvents FilterHideFiltersButton As New Button

' assign properties, styles, etc.
With Me.FilterShowFiltersButton
.ID = "FilterShowFiltersButton"
.Attributes.Add("class", "button")
.Text = "Show Filter Options"
.Attributes.Add("onclick", "call ShowFilters()")
End With

With Me.FilterHideFiltersButton
.ID = "FilterHideFiltersButton"
.Attributes.Add("Class", "button")
.Text = "Hide Filter Options"
.Attributes.Add("onclick", "call HideFilters()")
End With
 
J

Jacob Yang [MSFT]

Hi Susan,

By checking the source code, it is noticed that the button that will invoke
the HideFilters() vbscript is a server-side web server control, which, by
default, will raise a postback when a clicked was imposed on it. In this
case, the result of executing the script inside the HideFilters() function
will be overridden by a new postback.

To avoid such a situation,

1. Encapsulate all the code that render the embedded table inside the "If
Not IsPostBack" code block. For example,

If Not IsPostBack Then
' code to create the embedded table goes here...
End If

2. Render a standard html button, that is <input type=button onclick='call
HideFilters()'>, to do the same thing, instead of using a server-side
button that will raise a postback.

Please let me know if it makes sense.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Shawn Mehaffie

Unless you have code on the server that also needs to run remove the
runat="server" from the TableRowID. What is happening is that the row
dissapears, then the server-side code takes over and a post is done then the
event code is run (if there is any). The form post causes all controls to
be loaded with thier initial values, which is why the item reappear again.If
you do not have any code that needs to run on the server side, by
eliminating the runat="server" tag you eliminate the posting of the form.

If you do have server side code that needs to run, then another option would
be to not use client-side code and simply use the FilterRow.Visible=False
command and the row will stay invisible. If there are multiple rows with
the same name in the main table you might have to get a little bit fancier
and use the FindControl method of the main table and then set the visible
property to false. Feel free to contact me if you have any questions about
the 2 options I have given you.

S. Shawn Mehaffie
(e-mail address removed)
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top