kriskramer
asked on
Suppressing postback on a user control
I have a user control for a web site that shows a button called What Now. The page Load pulls the data that needs to be shown on this control, and the ascx page itself contains javascript to hide/unhide the control/tooltip. The problem, however, is that everytime you click the control to hide or unhide, it's making a server trip for some reason, and resetting. Anyone know why?
Here's the ascx page.
*************************
<div id="divWhatNowButton" class="what_now_top_bg" style="WIDTH:551px" onmouseover="ShowTip(23, event, 0)" onmouseout="HideTip(23, event)">
<input type="image" id="imgWhatNowButton" height="33" width="551" src="images/top_center_tit le.gif" alt="Display/Hide the What Now help message." onclick="javascript:toggle WhatNow(); ">
</div>
<div align="left" id="divWhatNowText" style="WIDTH:552px;BORDER- BOTTOM:1px solid;HEIGHT:16px">
<table border="0" cellpadding="5" width="100%">
<tr align="left" valign="top">
<td><asp:label id="lblToolTip" runat="server" cssclass="instructions"></ asp:label> </td>
</tr>
</table>
</div>
<script language="javascript" type="text/javascript">
<!--
//toggleWhatNow();
function toggleWhatNow() {
//toggles display of "What Now" and sets the session cookie (not persistant)
var iVisible = readCookie('ShowWhatNow');
var oToolTip = document.all('divWhatNowTe xt').style ;
alert('bVisible = ' + iVisible);
if (iVisible == null) {
iVisible = 1;
}
else if (iVisible == 0) {
iVisible = 1;
}
else {
iVisible = 0;
}
//alert('iVisible = ' + iVisible);
if (iVisible == 1) {
oToolTip.display = 'none';
}
else {
oToolTip.display = 'block';
}
writeCookie('ShowWhatNow', iVisible);
return false
}
//-->
</script>
And here's the vb code.
************************** **
Public WhatNowID As Integer = 0
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim bVisible As Boolean = False
Dim sToolTip As String = ""
If WhatNowID <> 0 Then
sToolTip = clsMiscUtil.ToolTipGet(Wha tNowID, ucHeader1.oSession)
Else
sToolTip = WhatNowID.ToString()
End If
lblToolTip.Text = sToolTip
End Sub
Here's the ascx page.
*************************
<div id="divWhatNowButton" class="what_now_top_bg" style="WIDTH:551px" onmouseover="ShowTip(23, event, 0)" onmouseout="HideTip(23, event)">
<input type="image" id="imgWhatNowButton" height="33" width="551" src="images/top_center_tit
</div>
<div align="left" id="divWhatNowText" style="WIDTH:552px;BORDER-
<table border="0" cellpadding="5" width="100%">
<tr align="left" valign="top">
<td><asp:label id="lblToolTip" runat="server" cssclass="instructions"></
</tr>
</table>
</div>
<script language="javascript" type="text/javascript">
<!--
//toggleWhatNow();
function toggleWhatNow() {
//toggles display of "What Now" and sets the session cookie (not persistant)
var iVisible = readCookie('ShowWhatNow');
var oToolTip = document.all('divWhatNowTe
alert('bVisible = ' + iVisible);
if (iVisible == null) {
iVisible = 1;
}
else if (iVisible == 0) {
iVisible = 1;
}
else {
iVisible = 0;
}
//alert('iVisible = ' + iVisible);
if (iVisible == 1) {
oToolTip.display = 'none';
}
else {
oToolTip.display = 'block';
}
writeCookie('ShowWhatNow',
return false
}
//-->
</script>
And here's the vb code.
**************************
Public WhatNowID As Integer = 0
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim bVisible As Boolean = False
Dim sToolTip As String = ""
If WhatNowID <> 0 Then
sToolTip = clsMiscUtil.ToolTipGet(Wha
Else
sToolTip = WhatNowID.ToString()
End If
lblToolTip.Text = sToolTip
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it. What's the difference? Why does using return keep it from posting back?
Simply, the page will not be posted back if the javascript function return false.
ASKER