Issues sending data back to server

K

K Viltersten

I've used the following

<input type="hidden" ID="Carrier" runat="server" value="abc" />

Then, in JS i set the value to "oink". I've checked using a debugger that
the value actually resides in that component. As the page gets requested
back from the server, i also issue the following.

Button1.Text = Carrier.Value + "#";

I'd expect to see "oink#" but instead i see "abc#". Why, oh why... I've
tested without explicit assignment of value but that only leads to "#" as
a result.

<input type="hidden" ID="Carrier" runat="server" />

What can i be doing wrong? What more can i check?
 
T

Teemu Keiski

Still fighting? :)

You probably set the Button's Text in Page_Load (since that's what I told
you to do), I failed to mention that Page_Load runs on every request. And
essentially this means that the posted value is overwritten, unless you
check in Page_Load for a postback or use directly Button's click event.

Let me put you a fully working test page here:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="WebApplication2.WebForm1" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="hidden" id="myHidden" runat="server" /><asp:Button
ID="btnSend"
runat="server" Text="Send and append the value to LinkButton's
Text"
onclick="btnSend_Click" /><br />
<asp:LinkButton ID="linkButton" runat="server" />
<script type="text/javascript" >
document.getElementById('myHidden').value = (new
Date()).toString();
alert('Value of myHidden is now ' +
document.getElementById('myHidden').value);
</script>
</div>
</form>
</body>
</html>


WebForm1.aspx.cs
================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void btnSend_Click(object sender, EventArgs e)
{

linkButton.Text += myHidden.Value + ",<br />";
}


}
}



--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net




I've used the following

<input type="hidden" ID="Carrier" runat="server" value="abc" />

Then, in JS i set the value to "oink". I've checked using a debugger that
the value actually resides in that component. As the page gets requested
back from the server, i also issue the following.

Button1.Text = Carrier.Value + "#";

I'd expect to see "oink#" but instead i see "abc#". Why, oh why... I've
tested without explicit assignment of value but that only leads to "#" as
a result.

<input type="hidden" ID="Carrier" runat="server" />

What can i be doing wrong? What more can i check?
 

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,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top