473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

ValueChanged Event Doesn't Fire

I'm trying to pass two values from client script (Javascript) to the
code-behind for a page using three hidden fields - two to hold the values and
a third to fire the ValueChanged event.

I have tried every method I can think of to get the event to fire, but it
will not, so either I am missing some code or am misunderstanding the nature
of the event. If anyone can review the test code posted below (which I
created to try to debug the problem) and provide some help, it would be much
appreciated.

What I'm doing is using a Javascript function (moveValues()) to copy
whatever is typed into the two text boxes to the hidden fields, and also
change the value of the third hidden field in an attempt to fire the event.
I've used the VS2005 debugging facility to confirm that the Javascript
function is working correctly; however, the c# code is never called.

Web form code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="HFTest" %>

<!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>Hidden Field Test</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="HiddenField1" runat="server" value="" />
<asp:HiddenField ID="HiddenField2" runat="server" value="" />
<asp:HiddenField ID="HiddenField3" runat="server" value=""
OnValueChanged="OnHiddenValuesChanged" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveValues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>

Javascript function:
function moveValues()
{
var txt1 = document.getElementById('Text1').getAttribute('val ue');
var txt2 = document.getElementById('Text2').getAttribute('val ue');
document.getElementById('HiddenField1').setAttribu te('value', txt1);
document.getElementById('HiddenField2').setAttribu te('value', txt2);

form1.HiddenField3.value = 'change';
}

Code-behind function:
protected void OnHiddenValuesChanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder("<b>Text Box 1: </b>");
sb.Append(HiddenField1.Value);
sb.Append("<br />");
sb.Append("<b>Text Box 2: </b>");
sb.Append(HiddenField2.Value);

results.InnerHtml = sb.ToString();
}

Oct 26 '06 #1
3 4726
Your OnHiddenValuesChanged eventhander is only going to be fired if there is
a postback. From the looks of what code you posted, all you have is a
client-side script function that changes the values.
Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rfinch" wrote:
I'm trying to pass two values from client script (Javascript) to the
code-behind for a page using three hidden fields - two to hold the values and
a third to fire the ValueChanged event.

I have tried every method I can think of to get the event to fire, but it
will not, so either I am missing some code or am misunderstanding the nature
of the event. If anyone can review the test code posted below (which I
created to try to debug the problem) and provide some help, it would be much
appreciated.

What I'm doing is using a Javascript function (moveValues()) to copy
whatever is typed into the two text boxes to the hidden fields, and also
change the value of the third hidden field in an attempt to fire the event.
I've used the VS2005 debugging facility to confirm that the Javascript
function is working correctly; however, the c# code is never called.

Web form code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="HFTest" %>

<!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>Hidden Field Test</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="HiddenField1" runat="server" value="" />
<asp:HiddenField ID="HiddenField2" runat="server" value="" />
<asp:HiddenField ID="HiddenField3" runat="server" value=""
OnValueChanged="OnHiddenValuesChanged" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveValues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>

Javascript function:
function moveValues()
{
var txt1 = document.getElementById('Text1').getAttribute('val ue');
var txt2 = document.getElementById('Text2').getAttribute('val ue');
document.getElementById('HiddenField1').setAttribu te('value', txt1);
document.getElementById('HiddenField2').setAttribu te('value', txt2);

form1.HiddenField3.value = 'change';
}

Code-behind function:
protected void OnHiddenValuesChanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder("<b>Text Box 1: </b>");
sb.Append(HiddenField1.Value);
sb.Append("<br />");
sb.Append("<b>Text Box 2: </b>");
sb.Append(HiddenField2.Value);

results.InnerHtml = sb.ToString();
}
Oct 26 '06 #2
Hi Peter -

Yes, it does, as I suspected it might have something to do with that. I'm
trying to work out how I can force a postback. Any pointers?

Cheers,
Ron

"Peter Bromberg [C# MVP]" wrote:
Your OnHiddenValuesChanged eventhander is only going to be fired if there is
a postback. From the looks of what code you posted, all you have is a
client-side script function that changes the values.
Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rfinch" wrote:
I'm trying to pass two values from client script (Javascript) to the
code-behind for a page using three hidden fields - two to hold the values and
a third to fire the ValueChanged event.

I have tried every method I can think of to get the event to fire, but it
will not, so either I am missing some code or am misunderstanding the nature
of the event. If anyone can review the test code posted below (which I
created to try to debug the problem) and provide some help, it would be much
appreciated.

What I'm doing is using a Javascript function (moveValues()) to copy
whatever is typed into the two text boxes to the hidden fields, and also
change the value of the third hidden field in an attempt to fire the event.
I've used the VS2005 debugging facility to confirm that the Javascript
function is working correctly; however, the c# code is never called.

Web form code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="HFTest" %>

<!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>Hidden Field Test</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="HiddenField1" runat="server" value="" />
<asp:HiddenField ID="HiddenField2" runat="server" value="" />
<asp:HiddenField ID="HiddenField3" runat="server" value=""
OnValueChanged="OnHiddenValuesChanged" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveValues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>

Javascript function:
function moveValues()
{
var txt1 = document.getElementById('Text1').getAttribute('val ue');
var txt2 = document.getElementById('Text2').getAttribute('val ue');
document.getElementById('HiddenField1').setAttribu te('value', txt1);
document.getElementById('HiddenField2').setAttribu te('value', txt2);

form1.HiddenField3.value = 'change';
}

Code-behind function:
protected void OnHiddenValuesChanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder("<b>Text Box 1: </b>");
sb.Append(HiddenField1.Value);
sb.Append("<br />");
sb.Append("<b>Text Box 2: </b>");
sb.Append(HiddenField2.Value);

results.InnerHtml = sb.ToString();
}
Oct 26 '06 #3
Ok, well the simplest way to create a postback is to have a control that
when changed, will create one by having it's AutoPostBack property set to
"true". A Button will always create a postback, all you need to do is click
it.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rfinch" wrote:
Hi Peter -

Yes, it does, as I suspected it might have something to do with that. I'm
trying to work out how I can force a postback. Any pointers?

Cheers,
Ron

"Peter Bromberg [C# MVP]" wrote:
Your OnHiddenValuesChanged eventhander is only going to be fired if there is
a postback. From the looks of what code you posted, all you have is a
client-side script function that changes the values.
Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"rfinch" wrote:
I'm trying to pass two values from client script (Javascript) to the
code-behind for a page using three hidden fields - two to hold the values and
a third to fire the ValueChanged event.
>
I have tried every method I can think of to get the event to fire, but it
will not, so either I am missing some code or am misunderstanding the nature
of the event. If anyone can review the test code posted below (which I
created to try to debug the problem) and provide some help, it would be much
appreciated.
>
What I'm doing is using a Javascript function (moveValues()) to copy
whatever is typed into the two text boxes to the hidden fields, and also
change the value of the third hidden field in an attempt to fire the event.
I've used the VS2005 debugging facility to confirm that the Javascript
function is working correctly; however, the c# code is never called.
>
Web form code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="HFTest" %>
>
<!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>Hidden Field Test</title>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:HiddenField ID="HiddenField1" runat="server" value="" />
<asp:HiddenField ID="HiddenField2" runat="server" value="" />
<asp:HiddenField ID="HiddenField3" runat="server" value=""
OnValueChanged="OnHiddenValuesChanged" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveValues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>
>
Javascript function:
function moveValues()
{
var txt1 = document.getElementById('Text1').getAttribute('val ue');
var txt2 = document.getElementById('Text2').getAttribute('val ue');
document.getElementById('HiddenField1').setAttribu te('value', txt1);
document.getElementById('HiddenField2').setAttribu te('value', txt2);
>
form1.HiddenField3.value = 'change';
}
>
Code-behind function:
protected void OnHiddenValuesChanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder("<b>Text Box 1: </b>");
sb.Append(HiddenField1.Value);
sb.Append("<br />");
sb.Append("<b>Text Box 2: </b>");
sb.Append(HiddenField2.Value);
>
results.InnerHtml = sb.ToString();
}
>
Oct 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kicksave | last post by:
I've run across an interesting issue. On my development server (a Windows 2000 box), the onload event inside the <body> tag on .asp pages will not fire. Even if I take the time to build a...
0
by: Alex Stevens | last post by:
Hi, I have a page in which I've added code to the Page_Load event. I send the url to a user in an email, and they click on it to activate an account. I put a breakpoint on the first execuable...
3
by: KathyB | last post by:
Hi, clearly I'm just not getting something here. I have an aspx form with ONE textbox and several label controls on it. I have the textbox set to AutoPostBack = True, but when I enter my text...
2
by: hn | last post by:
Hi, I have linkbuttons created dynamically and they display fine on the web page. However, when I click on the those link buttons, the event doesn't fire. Please tell me what's wrong with the...
1
by: Jack | last post by:
Hello, I have a dropdown list on a user control and the AutoPostBack property is set to True. I want to use the SelectedIndexChanged event to populate some text boxes based on what the user...
2
by: kgadia | last post by:
Hi, I have implemented global exception handler using http module by intercepting the Error event. The code works fine on my machine but the error event fails to fire when deployed on the...
4
by: Mark Olbert | last post by:
I'm trying to understand how to respond to mode changing events in a FormView control. I'm not using datasource controls, so I have to do more of the plumbing myself. Do I have to call the...
4
by: suzanne.boyle | last post by:
Hi, I'm adding an ImageButton as a child to a custom web control and attaching an event handler to it. When the page posts back the event is not being fired however. I initially assumed I had...
4
by: bbobely | last post by:
I have a generic subform control (subMain) whose sourceobject changes based on a combobox selection. Each sourceobject is a separate subform. These subforms (subsub1, subsub2 etc) have a field whose...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.