[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Suppressing postback on a user control

Posted on 2004-09-07
4
Medium Priority
?
325 Views
Last Modified: 2011-10-03
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_title.gif" alt="Display/Hide the What Now help message." onclick="javascript:toggleWhatNow();">
</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('divWhatNowText').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(WhatNowID, ucHeader1.oSession)
        Else
            sToolTip = WhatNowID.ToString()
        End If

        lblToolTip.Text = sToolTip

    End Sub
0
Comment
Question by:kriskramer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:kriskramer
ID: 11997975
Ok. I put the user control outside of the form on the page and it works like it's intended now, however, this control is designed to be in the middle of the page, between other controls that DO need to be in the form tag. Is there anyway to put this control back between the form tags and suppress the postback?
0
 
LVL 20

Accepted Solution

by:
ihenry earned 500 total points
ID: 11997987
try to modify this line

onclick="javascript:toggleWhatNow();

to

onclick="javascript:return toggleWhatNow();
0
 

Author Comment

by:kriskramer
ID: 11998208
That did it. What's the difference? Why does using return keep it from posting back?
0
 
LVL 20

Expert Comment

by:ihenry
ID: 11998221
Simply, the page will not be posted back if the javascript function return false.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question