Can OnTextChanged or other property, invoke a javascript script and not a VB script?
If so, how?
And, how is the “textfield.value” referenced?
And, how is a databound text field value referenced? Usually, it is part of "textfield.value"
OnTextChanged is the server side event. If you are looking to only execute some javascript, you will use the onchange attribute of your TextBox and call javascript function.
Hi Bill,
I want to implement this method to all the form variables. But When I did that I get the obeject required error. I am assigning the value of the flag whenever the txt is changed in the 2 text boxes. So when I click the submit button, I do some processing based
on the value of the flag. It works for mytxt, but throws the Object required error for mycmt.
I pasted the code. Can you help me?
I am not sure about the object required error except maybe the document.all.txtFlag isn't working as you expect it to. First document.all is an IE only thing, so I would switch to use document.getElementById( "" ).
Now this requires that the ID attributes be on the html element of the flag you are setting. Also since you aren't concerned with what changed on the text boxes and are setting the same flag, I have combined the methods into one.
Here is my html that I used to test out the function.
The onchange attribute might not show up in the intellisense, but if you manually type it, it will be rendered. TextBox, like all WebControls implement the IAttributeAccessor interface. What this means is any attributes you provide (like "onchange")
that don't have a corresponding property on the control will be rendered just as an attribute pair.
Sorry I should have been more specific. I want to pass the commandargument to a server-side function.
The server side code lookes like this:
Public Sub contactClick(ByVal sender
As Object,
ByVal e As CommandEventArgs)
lblEmpNo.Text = e.CommandArgument
End Sub
so, back on the client side I would like to pass the .Text value of a label as the commandargument for the linkbutton:
<asp:linkbutton id="lbRegEEOContact" runat="server" Width="214px" OnCommand="contactClick" CommandArgument="lblHiddenEEOEmpNo.Text">
It is not evaluating lblHiddenEEOEmpNo.Text to the value no matter what I do. I know there must be a specific syntax to refer to the asp.net control's value, so that's what I'm looking for. I've tried <%= controlname.Text%> and severalo variations but it
alwasy evaluates to the name of the control.
There might be a way to accomplish this html side, but you will have to use DataBinding syntax. I would recommend setting the CommandArgment on the code behind. Somewhere in your code you are setting the lblHiddenEEOEmplNo.Text. When you set
it, you can set the CommandArgument of the LinkButton there.
lblHiddenEEOEmplNo.Text = 'some text
lbRegEEOCantact.CommandArgument = lblHiddenEEOEmplNo.Text
Then in your CommandEvent of your link button, you will have the command argument set properly. Rather than placing this item in a hidden label, you also could place this string into the ViewState of the page.
Please Indicate "Mark as Answer" if a Post has Answered the Question
-----------------------
Sameer Kulkarni.
Programmer Analyst @ mnop.in
My blog - http://geekospace.com/
-----------------------
GeorgeSmith
Member
120 Points
24 Posts
Using OnTextChanged to call a JavaScript
Aug 29, 2005 04:04 PM|LINK
If so, how?
And, how is the “textfield.value” referenced?
And, how is a databound text field value referenced? Usually, it is part of "textfield.value"
Thanks. Much appreciated.
George
billrob458
Contributor
3329 Points
671 Posts
Re: Using OnTextChanged to call a JavaScript
Aug 29, 2005 05:28 PM|LINK
OnTextChanged is the server side event. If you are looking to only execute some javascript, you will use the onchange attribute of your TextBox and call javascript function.
<script language="javascript">
function Changed( textControl )
{
alert( textControl.value );
}
</script>
<asp:TextBox id="txtName" runat="server" onchange="javascript: Changed( this );" />
bill
chennaichitt...
Member
5 Points
1 Post
Re: Using OnTextChanged to call a JavaScript
Sep 06, 2005 03:35 PM|LINK
I want to implement this method to all the form variables. But When I did that I get the obeject required error. I am assigning the value of the flag whenever the txt is changed in the 2 text boxes. So when I click the submit button, I do some processing based on the value of the flag. It works for mytxt, but throws the Object required error for mycmt.
I pasted the code. Can you help me?
<script language=javascript> function txtChanged( txtForecastDesc) { document.all.txtFlag.value = 1; } </script> <script language=javascript> function txtChanged( txtForecastDesc) { document.all.txtFlag.value = 1; } </script>
script
language = javascript>function txtChanged( mytxt)
{
document.all.txtFlag.value = 1;
}
</script>
script language = javascript>
function cmtChanged( mycmt)
{
document.all.txtFlag.value = 1;
}
</script>
<
ASP:TEXTBOX CLASS="inputleft" ID="mytxt" RUNAT="server" WIDTH="392px" ROWS="1" COLUMNS="80"MAXLENGTH="80" onchange="javascript: txtChanged( this );" ></ASP:TEXTBOX><
ASP:TEXTBOX CLASS="inputleft" ID="mycmt" onchange="javascript: cmtChanged( this );" RUNAT="server" WIDTH="648px" HEIGHT="120px" ></ASP:TEXTBOX>billrob458
Contributor
3329 Points
671 Posts
Re: Using OnTextChanged to call a JavaScript
Sep 06, 2005 07:10 PM|LINK
Now this requires that the ID attributes be on the html element of the flag you are setting. Also since you aren't concerned with what changed on the text boxes and are setting the same flag, I have combined the methods into one.
Here is my html that I used to test out the function.
<form runat="server">
<input type="hidden" id="txtFlag" name="txtFlag">
<script language="javascript">
function SetFlag()
{
document.getElementById( "txtFlag" ).value = 1;
}
</script>
<ASP:TEXTBOX CLASS="inputleft" ID="mytxt" RUNAT="server" WIDTH="392px" ROWS="1" COLUMNS="80"
MAXLENGTH="80" onchange="javascript: SetFlag();"></ASP:TEXTBOX>
<ASP:TEXTBOX CLASS="inputleft" ID="mycmt" onchange="javascript: SetFlag();" RUNAT="server"
WIDTH="648px" HEIGHT="120px"></ASP:TEXTBOX>
<input type="button" ID="btnSubmit" Runat="server" onclick="javascript: alert( document.getElementById( 'txtFlag' ).value );">
</form>
Mr Flibble
Member
15 Points
3 Posts
Re: Using OnTextChanged to call a JavaScript
Sep 20, 2005 02:21 PM|LINK
I don't seem to have an onchange property for my asp:TextBox control - any suggestions anybody?
Note: I'm forced to use .Net 2002 so I don't know if this is the problem.
Thanks
billrob458
Contributor
3329 Points
671 Posts
Re: Using OnTextChanged to call a JavaScript
Sep 20, 2005 04:30 PM|LINK
<asp:TextBox id="txt" runat="server" custom="true" Text="Hello" />
will essentially be rendered as
<input type="text" id="txt" name="txt" custom="true" value="Hello" />
Just try manually typing it in and it should work.
However, you can also set this in the codebehind. Using txtFlag as your text box.
Page_Load
txtFlag.Attributes["onchange"] = "javascript: Changed( this );";
HTH,
bill
BooBoo
Member
20 Points
4 Posts
Re: Using OnTextChanged to call a JavaScript
Sep 20, 2005 05:21 PM|LINK
The server side code lookes like this:
Public Sub contactClick(ByVal sender As Object, ByVal e As CommandEventArgs)
lblEmpNo.Text = e.CommandArgument
End Sub
so, back on the client side I would like to pass the .Text value of a label as the commandargument for the linkbutton:
<asp:linkbutton id="lbRegEEOContact" runat="server" Width="214px" OnCommand="contactClick" CommandArgument="lblHiddenEEOEmpNo.Text">
It is not evaluating lblHiddenEEOEmpNo.Text to the value no matter what I do. I know there must be a specific syntax to refer to the asp.net control's value, so that's what I'm looking for. I've tried <%= controlname.Text%> and severalo variations but it alwasy evaluates to the name of the control.
Hopefully somebody can help me with this. . .
Thanks!
billrob458
Contributor
3329 Points
671 Posts
Re: Using OnTextChanged to call a JavaScript
Sep 20, 2005 06:13 PM|LINK
lblHiddenEEOEmplNo.Text = 'some text
lbRegEEOCantact.CommandArgument = lblHiddenEEOEmplNo.Text
Then in your CommandEvent of your link button, you will have the command argument set properly. Rather than placing this item in a hidden label, you also could place this string into the ViewState of the page.
bill
SameerKulkar...
Member
195 Points
110 Posts
Re: Using OnTextChanged to call a JavaScript
Jan 21, 2011 05:18 AM|LINK
can any one help me . .http://forums.asp.net/p/1644592/4263178.aspx#4263178
-----------------------
Sameer Kulkarni.
Programmer Analyst @ mnop.in
My blog - http://geekospace.com/
-----------------------