Hidden Field that is set on server side...not getting the last updated value from client?

Hi,

I have a hidden field that tracks errors in my server side asp.net 2.0 code.  However, when I set the value to an error (from it's default value "NotSet") in the server side code and then when trying to access that Hidden Variable from the client the value is still set to the default value, "NotSet" instead of the error information.

Any ideas as to what is going on here?

Thanks in advance!

 

Server Side.... 

catch (Exception er)

{

Errors.Value = er.Message;

o o o

}

Client Side....

function getErrors()

{

var cho = document.getElementById('<%=Errors.ClientID %>');

alert(cho.value);

return false;

}

0
JacquoJohnson
4/28/2007 7:55:50 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

4 Replies
820 Views

Similar Articles

[PageSpeed] 49

Are you sure the exception is being triggered?

You could try this:

Errors.Value = er.Message;
Response.Write("Setting Error to: " + er.Message);

 


Steve Wellens

My blog
0
SGWellens
4/29/2007 3:10:36 PM

Thanks for the reply Steve.  Yes the exception is getting thrown.  Even if I set the value explicitly with some trivial string literal

Errors.Value = "Whatever"

It is still not getting set over on the client side.

Thanks.

0
JacquoJohnson
4/30/2007 2:12:01 AM
Is there any other code that "touches" the hidden control...perhaps initializing it to an empty string?
Steve Wellens

My blog
0
SGWellens
4/30/2007 2:34:09 AM
JacquoJohnson:

Hi,

I have a hidden field that tracks errors in my server side asp.net 2.0 code.  However, when I set the value to an error (from it's default value "NotSet") in the server side code and then when trying to access that Hidden Variable from the client the value is still set to the default value, "NotSet" instead of the error information.

Any ideas as to what is going on here?

Thanks in advance!

 

Server Side.... 

catch (Exception er)

{

Errors.Value = er.Message;

o o o

}

Client Side....

function getErrors()

{

var cho = document.getElementById('<%=Errors.ClientID %>');

alert(cho.value);

return false;

}

Hi,

Try to use document.getElementById("Errors");

Here is sample for you which I write:

<%@ Page Language="C#" %>

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

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        Errors.Value = "Hello";
    }
</script>

<script type="text/javascript">
function showup()
{
    var pp = document.getElementById("Errors");
    alert(pp.value);   
}


</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input id="Errors" runat="server" type="hidden" />
    <input id="bt1"  value="Click Me" type="button" onclick="showup()" />
    </div>
    </form>
</body>
</html>

Happy coding.


Please give us feedback no matter whether you get your answer.
Please "mark as answer" if it's useful for you

Sincerely,
Jerome
0
Jerome
5/1/2007 3:46:13 AM
Reply:

Similar Artilces:

Getting hidden variable value from server side in client side
hi,        I am struck in problem. I have a hidden field in my form and i am setting some value in that.         Now i wnt to use this value from client side but i m not able to retrieve it. All i am getting there is an object.         I feel the hidden field is not able to hold that value.         <input type="hidden" id="hdnVar" runat="server" />         in code behind      ...

pls help: how to get client-side HTML "text field" value from a server side button
i copy some javascript from somewhere so user can choose pick up a date from a calendar and display the date onto a HTML text field. I have no knowledge in writing client side script(i.e. write code in html) can i write some code in a server-side button to get the value in the HTML text field??? i tried: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click textbox1.text = document.getElementById("htmltext").value End Sub but "document" is highlighted, and say isn't declar yet. and...

Use client side code to get hidden field value from calling page
Hi, I have a web application that is being called from an extranet app. I need to access the value of a hidden form variable on the calling form, I have tried Request.form("Fieldname") & cannot pick up any values. They are not keen on passing the value in the querystring - I would really appreciate some help on this. Thanks If the item is not in the form collection, then they're probably not doing a POST to your page. You can pass information to a page three ways: URL (querystring, fragment, etc), POST (form.submit()), and via a HTTP Header. They'll need to decide...

How to get the Client side values in server side code.
Hi all, i have a proble i need to get the client side javascript values in C# code at server side. how can i pass those values? i am using version 1.1, i kno thatwe can use callback events mechnisam in 2.0 or ajax ,apart from that how we can pass? My problem is i need to stop the execution of the code based on after reciving values from the client   any ideas please???   Million thanks RamCheersRam MCP Hello Ram, a common approach is from javascript set an hidden field, then issue a postback. On the server-side, handle the post-back. Feel free to go deeper in your que...

superreview requested: [Bug 232892] imap folders which get new mail filtered nto them by client-side filters not getting counts updated or green arrow : [Attachment 140616] fix for cross server case
David Bienvenu <bienvenu@nventure.com> has asked Scott MacGregor <mscott@mozilla.org> for superreview: Bug 232892: imap folders which get new mail filtered nto them by client-side filters not getting counts updated or green arrow http://bugzilla.mozilla.org/show_bug.cgi?id=232892 Attachment 140616: fix for cross server case http://bugzilla.mozilla.org/attachment.cgi?id=140616&action=edit ...

superreview granted: [Bug 232892] imap folders which get new mail filtered nto them by client-side filters not getting counts updated or green arrow : [Attachment 140616] fix for cross server case
Scott MacGregor <mscott@mozilla.org> has granted David Bienvenu <bienvenu@nventure.com>'s request for superreview: Bug 232892: imap folders which get new mail filtered nto them by client-side filters not getting counts updated or green arrow http://bugzilla.mozilla.org/show_bug.cgi?id=232892 Attachment 140616: fix for cross server case http://bugzilla.mozilla.org/attachment.cgi?id=140616&action=edit ...

hidden field value not getting set
Below is code to generate one or two forms... When both forms are generated the "hidden" value for the second form is not getting replaced with the "correct" value... Does anyone see a problem with this code ? Thanks in advance ... print $q->p($q->center( "Items from $REQUEST{START} to $displayed of $REQUEST{END} items")); # <-- values OK here ! exit if $REQUEST{END} <= $max_lines; # No "Previous" or "Next" # Display previous & next buttons when appropriate my $span = 9; ...

How can I set client side values as server side values?
Hi, Can anyone tell me how I can get client side values such as document.referrer, navigator.appName etc... into server side scripts? There are some client side values I'd like to set as session vars and insert into the db? How do I go about this? Thanks for any pointers Davlon PS (I'm using powersite 7.1.0.300) Pass them as page parameters, e.g., http://myserver/myurl?document.referrer=whatever&navigator.appName=yadayada Then, in your server-side script, just loop through the document.value array and get these values. -- pbm_hopethishelps, Roy Kie...

Get label value on server side set by javascript
 HelloHow are all here.I have set the label text using javascriptdocument.getElementById("lblEmail").innerHTML = Login;Now when I try to get value (i.e. Text), by lblEmail.Text on ASP.Net server page, then the label shows no value or text. i.e. it is empty. why this is happening? how can I get value on Form set by Javascript?regards change in coding document.getElementById("lblEmail").value= "Hello World";   Please remember to click "Mark as Answer" on the post that helps you. This can be beneficial to other community members reading th...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on asp.net, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

how can I get values of client side properties on the server
I define an img on the html like this:<img src=........  id=...   runat=server>I assign the value to src in javascript functions.My question: how do I get that src value on the server using c# or Vb.NetI tried this:  this.findcontrol(img.clientId)but what s next, how do I get the client side attributes like src, style properties and son on plsAnd vice versa, If I define server controls:  <asp:textbox id=myTextBox runat=server...>How do I access the properties of myTextBox  in javascript client side code so I can read them and eventually change themTh...

Client side set hidden field value not POSTing back
 hi,(sorry, I dont have any code snippets to hand as I'm away from the dev machine at the mo)I have a page which makes two seperate WebServce calls for data. One is via an Ajax call, the other is server side.The flow is as follows:1. Ajax Web Service call returns a collection2. In the js script file, read the PK's of the collection and set a hiddenfield with the comma-seperated keys3. initiate a __doPostBack call from script - target an update panel on the page which then calls the second Web ServiceThe problem I am experiencing is that after I have made the first call and ...

Getting a value set with javascript from a hidden field on a page event
Hello to all there, thanks for reading this topic in advance and for your time. I am trying to retrieve a value from a hiddenfield that has the screen resolution value captured with previous embed javascript, the script is at the ending part of the body tag, and works well because i have tested showing the value ussing a msgbox ussing a button, but well, the idea for me is to retrieve the value on an event page as load for example, so the objects that i want to change the position according each type of resolution do this automatically changing their classes names to ones that are ...

Getting my client-side variable over to server-side
Ok so I have looked at a few posts on this subject and I can't quite figure out how to apply the idea to what I am doing here. I am using javascript to take amounts from 7 different textboxes and add them up on the fly, dropping the total in the 8th textbox. After they fill in that information they click button (postback) to continue throughout the form... what I need is for the "textboxTotalAmt" to move from client-side to server-side.  So I can access that total amount later in the form. Here is the Javascript piece... <script type="text/java...

Web resources about - Hidden Field that is set on server side...not getting the last updated value from client? - asp.net.getting-started

10 things to buy this Black Friday to survive the next one
Black Friday is the tradition of taking the year's worth of rage you've built up, and pushing it onto the packs of rapid consumers for the prize ...

New York's Thanksgiving parade draws huge crowd amid tight security
Reuters New York's Thanksgiving parade draws huge crowd amid tight security Reuters NEW YORK Crowds of spectators watched the marching bands, ...

The $5 computer that can change the world
The world collectively dropped its jaw when the Raspberry Pi was first unveiled. A $35 computer that could be used to power just about anything? ...

Trump denies mocking New York Times reporter's disability
Republican presidential candidate Donald Trump denied on Thursday he was mocking the physical disability of a New York Times reporter during ...

Rebel Wilson Wishes Her Fans a Happy Pre-Thanksgiving!
Rebel Wilson is all smiles as she makes her way through Heathrow Airport on Wednesday (November 25) in London, England. The Pitch Perfect 2 ...

UPDATE 4-Britain's Cameron says time to bomb militants in Syria
Telegraph.co.uk UPDATE 4-Britain's Cameron says time to bomb militants in Syria Reuters ... * Cameron says Britain cannot subcontract defence. ...

New ‘Star Wars: The Force Awakens’ Spot Focuses on Adam Driver’s Kylo Ren
“Star Wars” has a Thanksgiving treat for impatient fans — a new, minute-long spot for “The Force Awakens,” which features a better look at Adam ...

Police detain two over Mali hotel attack: security sources
Malian special forces arrested two suspects Thursday over a siege at a luxury hotel in the capital Bamako that left 20 people dead, security ...

VIDEO: Russia spokesperson sets out Syria plan
Speaking to the BBC after the downing of a Russian warplane by a Turkish jet, Maria Zakharova, the Russian Foreign Ministry spokesperson, set ...

Pope Francis begins his first tour of Africa as people wait for a glimpse of him
Tens of thousands of people stood inside the University of Nairobi campus (pictured) and many more stood on muddy streets stretching several ...

Resources last updated: 11/27/2015 1:43:47 AM