Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2006, 05:26 PM
Authorized User
Points: 514, Level: 8
Points: 514, Level: 8 Points: 514, Level: 8 Points: 514, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hidden field won't turn blank

I'm using javascript to capture a text field value and put it in a hidden field value, and then submit the associated form. In Page_Load I extract and act on the hidden field value. All this works fine, except...

The hidden field value that is entered persists when the page is refreshed (ie. reloaded) via the browser UI, causing the field value to be recognized and acted on again in Page_Load.

I've tried to blank out the hidden field value in several different client-side and server side events, and can't seem to make it go away.

Any suggestions on how to fix this would be appreciated.

Thanks!

================= page and javascript

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script src=JScript.js></script>
</head>

<BODY onload="javascript:ResetHiddenFields()"; onunload="javascript:ResetHiddenFields()";>
    <form id="form1" method="post" runat="server">
     <div>
        <input type=hidden id="Hidden1" runat=server value = "" />
        <input id="Button1" type="button" style="z-index:103; left: 180px; position: absolute; top: 8px;" onClick="javascript:Button1Click()" value="button" />
        <input id="Text1" style="z-index: 104; left: 16px; position: absolute; top: 8px"
        type="text" />
     </div>

</form>

<script language=javascript>

function GetElem(varString){return document.getElementById(varString) }

function Button1Click() {
    GetElem("Hidden1").value = ""
    GetElem("Hidden1").value = GetElem("Text1").value
    alert("Hidden1 = " + GetElem("Hidden1").value);
    document.forms[0].submit();
    }

function ResetHiddenFields() {
    alert("resetting hidden value")
    GetElem("Hidden1").value = ""
    }
</script>

</body>
</html>


============= code behind

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            Me.Hidden1.Value = ""
        End If

        MsgBox("in Page_Load")
        If IsPostBack Then
            MsgBox("about to check hidden1")
            If Trim(Me.Hidden1.Value) <> "" Then ' doesn't help, because not blank at this point
                MsgBox("found non-blank hidden value = " & Me.Hidden1.Value)
                Me.Hidden1.Value = "" ' doesn't help
            End If
        End If

    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        Me.Hidden1.Value = "" ' didn't work
    End Sub

    Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
        'Me.Hidden1.Value = "" ' this shuts it off before load, so not found, not good
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        'Me.Hidden1.Value = "" ' didn't work
    End Sub

    Protected Sub form1_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Unload
        'Me.Hidden1.Value = "" ' didn't work
    End Sub

    Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
        'Me.Hidden1.Value = "" ' didn't work
    End Sub

    Protected Sub Hidden1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Hidden1.PreRender
        'Me.Hidden1.Value = "" ' didn't work
    End Sub
End Class

===============================================
Reply With Quote
  #2 (permalink)  
Old February 28th, 2006, 06:37 PM
Authorized User
Points: 514, Level: 8
Points: 514, Level: 8 Points: 514, Level: 8 Points: 514, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Apparently, I need a bigger post-it on the side of my computer screen, which says "DO SEARCHES BEFORE POSTING HELP REQUESTS".....

This is a known issue, not specific to ASP.NET, and this article (and others) provide lots of information (including the fact that it's non-trivial).

http://aspalliance.com/687#Page1
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pass value to the hidden field Dejitan ASP.NET 1.0 and 1.1 Basics 4 December 21st, 2006 03:13 AM
Hidden Field value error - PLEASE HELP jroxit Classic ASP Basics 5 September 18th, 2006 05:46 AM
Hidden field ashoka_klt ASP.NET 1.0 and 1.1 Basics 1 September 6th, 2006 07:12 AM
Validating a hidden field mkerchenski ASP.NET 1.0 and 1.1 Basics 1 June 3rd, 2004 11:20 AM
How to assign a value to a hidden field? Edward King Javascript How-To 1 May 3rd, 2004 07:36 AM



All times are GMT -4. The time now is 11:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.