473,544 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 misunderstandin g 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="Defau lt.aspx.cs"
Inherits="HFTes t" %>

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

<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:HiddenFiel d ID="HiddenField 1" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 2" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 3" runat="server" value=""
OnValueChanged= "OnHiddenValues Changed" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveVa lues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>

Javascript function:
function moveValues()
{
var txt1 = document.getEle mentById('Text1 ').getAttribute ('value');
var txt2 = document.getEle mentById('Text2 ').getAttribute ('value');
document.getEle mentById('Hidde nField1').setAt tribute('value' , txt1);
document.getEle mentById('Hidde nField2').setAt tribute('value' , txt2);

form1.HiddenFie ld3.value = 'change';
}

Code-behind function:
protected void OnHiddenValuesC hanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(" <b>Text Box 1: </b>");
sb.Append(Hidde nField1.Value);
sb.Append("<br />");
sb.Append("<b>T ext Box 2: </b>");
sb.Append(Hidde nField2.Value);

results.InnerHt ml = sb.ToString();
}

Oct 26 '06 #1
3 4744
Your OnHiddenValuesC hanged 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 misunderstandin g 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="Defau lt.aspx.cs"
Inherits="HFTes t" %>

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

<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:HiddenFiel d ID="HiddenField 1" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 2" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 3" runat="server" value=""
OnValueChanged= "OnHiddenValues Changed" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveVa lues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>

Javascript function:
function moveValues()
{
var txt1 = document.getEle mentById('Text1 ').getAttribute ('value');
var txt2 = document.getEle mentById('Text2 ').getAttribute ('value');
document.getEle mentById('Hidde nField1').setAt tribute('value' , txt1);
document.getEle mentById('Hidde nField2').setAt tribute('value' , txt2);

form1.HiddenFie ld3.value = 'change';
}

Code-behind function:
protected void OnHiddenValuesC hanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(" <b>Text Box 1: </b>");
sb.Append(Hidde nField1.Value);
sb.Append("<br />");
sb.Append("<b>T ext Box 2: </b>");
sb.Append(Hidde nField2.Value);

results.InnerHt ml = 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 OnHiddenValuesC hanged 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 misunderstandin g 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="Defau lt.aspx.cs"
Inherits="HFTes t" %>

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

<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:HiddenFiel d ID="HiddenField 1" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 2" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 3" runat="server" value=""
OnValueChanged= "OnHiddenValues Changed" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveVa lues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>

Javascript function:
function moveValues()
{
var txt1 = document.getEle mentById('Text1 ').getAttribute ('value');
var txt2 = document.getEle mentById('Text2 ').getAttribute ('value');
document.getEle mentById('Hidde nField1').setAt tribute('value' , txt1);
document.getEle mentById('Hidde nField2').setAt tribute('value' , txt2);

form1.HiddenFie ld3.value = 'change';
}

Code-behind function:
protected void OnHiddenValuesC hanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(" <b>Text Box 1: </b>");
sb.Append(Hidde nField1.Value);
sb.Append("<br />");
sb.Append("<b>T ext Box 2: </b>");
sb.Append(Hidde nField2.Value);

results.InnerHt ml = 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 OnHiddenValuesC hanged 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 misunderstandin g 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="Defau lt.aspx.cs"
Inherits="HFTes t" %>
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
>
<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:HiddenFiel d ID="HiddenField 1" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 2" runat="server" value="" />
<asp:HiddenFiel d ID="HiddenField 3" runat="server" value=""
OnValueChanged= "OnHiddenValues Changed" />
</div>
<div>
<input id="Text1" type="text" />
<br />
<input id="Text2" type="text" />
<br />
<input id="Button2" type="button" value="Submit"
onclick="moveVa lues()" />
<br />
</div>
<div id="results" runat="server">
</div>
</form>
</body>
</html>
>
Javascript function:
function moveValues()
{
var txt1 = document.getEle mentById('Text1 ').getAttribute ('value');
var txt2 = document.getEle mentById('Text2 ').getAttribute ('value');
document.getEle mentById('Hidde nField1').setAt tribute('value' , txt1);
document.getEle mentById('Hidde nField2').setAt tribute('value' , txt2);
>
form1.HiddenFie ld3.value = 'change';
}
>
Code-behind function:
protected void OnHiddenValuesC hanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder(" <b>Text Box 1: </b>");
sb.Append(Hidde nField1.Value);
sb.Append("<br />");
sb.Append("<b>T ext Box 2: </b>");
sb.Append(Hidde nField2.Value);
>
results.InnerHt ml = sb.ToString();
}
>
Oct 26 '06 #4

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

Similar topics

1
3880
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 "function window_onload()", the .asp page seems to ignore it. However, when I place the same code on my production server (also Windows 2000 Server) it...
0
342
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 line of code in the page load event. The breakpoint works fine when linked to from another page on the site, and
3
12317
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 and hit ENTER, nothing fires. Oddly enough, this is similar to the button problem I've just posted as well. I use similar code for the textbox...
2
3853
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 following code. Thanks. Dim lbtnQuestion As LinkButton = New LinkButton lbtnQuestion.Text = "Question " & (j + 1).ToString()
1
5717
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 chose in the dropdown list. However, the SelectedIndexChanged event doesn't fire. In the immediate window it appears that the index is not changing...
2
1603
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 test servers. The assembly containing the http module code has full control permissions to everyone.
4
8937
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 ChangeMode() method in the ModeChanging event handler? Why doesn't the ModeChanged event fire? I can see the mode in the process of changing, because my...
4
2084
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 missed some code or something however after playing about I've found that if I change the control to a Button (or a LinkButton) the event fires. ...
4
3268
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 onclick event is DoCmd.OpenForm "frmVendor". When subMain is loaded its default sourceobject is subsub1 and the onclick event works fine. However,...
0
7416
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7360
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
4906
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3400
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1833
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
983
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
653
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.