Hi, I have a JavaScript Function on a parent page, which returns the text value 'code', after a window has closed (OnClientClose()). The only thing I need to do now is to stuff the return value into a text box, which is a couple of UserControls down the
food chain, from the Parent Page (Inventory.aspx).
The user control within InventoryItem.aspx is called ucInventoryItem. Within ucInventoryItem is ucStamp, where txtCatCode resides.
I'm very new to JavaScript and would really appreciate any help that can be provided.
Thanks in advance,
<script
type="text/javascript">
//<![CDATA[
function
OnClientClose(code) {
// Here is where Ineed to set the value of
ucInventoryItem -> ucStamp -> txtCatCode.text to the value of code.
alert(code); // Check to see value of code is correct.... and thus far, it is!
Thank you so much for your help thus far - I'm ALMOST there!! After a few attempts, I ended up putting the following script on the User Control itself, and the following works GREAT... except for one tiny little thing...
After the above function is called - The new value (code) doesn't appear in the text box, until I click on the text box itself! Kinda strange... Is there some sort of a refresh method that I can throw into the function 'OnClientClose' that would somehow
simulate a user click, and therefore update the value of the textbox (without further user interaction, such a click)? Does that make sense?
Wow - That was weird. My original TextBox was actually a Telerik RadTextBox, which exhibited the same behavior even with the TextBox.focus() method. I replaced it with a standard ASP.NET TextBox and voila! It did the trick! Just as an FYI, the only other
thing I suspect may have caused this strange behavior was the fact that the pop-up window, triggered by the showcatalogsearch() function, is a Telerik RadWindow, and the RadWindowManager's properties may have had a part to play in this Wagnerian tragedy.
Anyway, I cannot thank you enough for your time and help! I owe you one.... Cheers!
We have the same problems with several telerik controls. I could get it to update the value if I took out the client side events. Not ideal of course because then you cannot detect client side changes. So we have gone down the same path as you and ditched
the telerik radTextBox in favour of a standard ASP text box. More than a bit annoying.
I have just finished working through this issue myself, although without the benefit of Telerik's support staff. The final resolution that I discovered did not match up with Telerik suggestions or their documentation. Obviously this reflects poorly on
Telerik to some extent, but I think it is more indicative of an environment which includes .NET 2.0, .NET 3.5, JavaScript, AJAX, Master Pages and is quickly becoming more complicated than it needs to be. When properties in Javascript are different from properties
in code behind from properties in Javascript with Master Pages, etc. then I think we are headed off the cliff -- if not today, then certainly tomorrow. Anyway, here is the solution I discovered:
function OnClientClose(oWnd, args) {
//get the transferred arguments
var arg = args.get_argument();
if (arg) {
var cityName = arg.cityName;
var seldate = arg.selDate;
var screenName;
screenName = document.getElementById("<%= MyScreenName.ClientID %>");
screenName.value = cityName;
screenName.set_displayvalue = cityName;
var a1;
var a2;
a1 = document.getElementById("<%= MyScreenName.ClientID %>" + "_text");
a1.value = cityName;
}
}
There is a certain lack of conceptual integrity in the variable names, etc. I apologize for that but this is a work in progress that started from a Telerik example.
The most notable factors are:
(1) cityname and seldate are variables on the RadWindow child;
(2) MyScreenName is a RadTextBox on the parent window;
(3) You must get addressability to the "generic" RadTextBox AND to the "_text" variant and set both of these values for the overall solution to work properly.
(4) The "generic" RadTextBox value is the actual internal, programmatic value of the control.
(5) The "_text" value is the displayed value of the control.
If I am not being clear, feel free to ask questions and I'll do my best to answer them.
wolfstatic
Member
12 Points
23 Posts
Using Javascript to set TextBox Value, embedded within a user control.
Jun 27, 2009 02:00 AM|LINK
Hi, I have a JavaScript Function on a parent page, which returns the text value 'code', after a window has closed (OnClientClose()). The only thing I need to do now is to stuff the return value into a text box, which is a couple of UserControls down the food chain, from the Parent Page (Inventory.aspx).
The user control within InventoryItem.aspx is called ucInventoryItem. Within ucInventoryItem is ucStamp, where txtCatCode resides.
I'm very new to JavaScript and would really appreciate any help that can be provided.
Thanks in advance,
<script type="text/javascript">
//<![CDATA[
function OnClientClose(code) {
// Here is where I need to set the value of ucInventoryItem -> ucStamp -> txtCatCode.text to the value of code.
alert(code); // Check to see value of code is correct.... and thus far, it is!
}
//]]>
</script>javascript usercontrol setting values
MetalAsp.Net
All-Star
112183 Points
18258 Posts
Moderator
Re: Using Javascript to set TextBox Value, embedded within a user control.
Jun 27, 2009 02:46 AM|LINK
Try it like this:
var txtCatCode = document.getElementById('<%= ucInventoryItem.FindControl("ucStamp").FindControl("txtCatCode").ClientID %>'); txtCatCode.value = code;wolfstatic
Member
12 Points
23 Posts
Re: Using Javascript to set TextBox Value, embedded within a user control.
Jun 29, 2009 05:15 PM|LINK
Hey MetalASP,
Thank you so much for your help thus far - I'm ALMOST there!! After a few attempts, I ended up putting the following script on the User Control itself, and the following works GREAT... except for one tiny little thing...
---------------------------------------------------------------------------
<script type="text/javascript">
//<![CDATA[function OnClientClose(code) {
var TextBox = document.getElementById('<%= FindControl("rtxtCatNoKey").ClientID %>');TextBox.value = code
}
//]]>
</
script>------------------------------------------------------
After the above function is called - The new value (code) doesn't appear in the text box, until I click on the text box itself! Kinda strange... Is there some sort of a refresh method that I can throw into the function 'OnClientClose' that would somehow simulate a user click, and therefore update the value of the textbox (without further user interaction, such a click)? Does that make sense?
Thanks again - this is really saving my life!
MetalAsp.Net
All-Star
112183 Points
18258 Posts
Moderator
Re: Using Javascript to set TextBox Value, embedded within a user control.
Jun 29, 2009 05:31 PM|LINK
If this code is in the user control itself, and rtxtCatNoKey is in the user control as well, there's no need for the FindControl method; simply use:
wolfstatic
Member
12 Points
23 Posts
Re: Using Javascript to set TextBox Value, embedded within a user control.
Jun 29, 2009 05:58 PM|LINK
Wow - That was weird. My original TextBox was actually a Telerik RadTextBox, which exhibited the same behavior even with the TextBox.focus() method. I replaced it with a standard ASP.NET TextBox and voila! It did the trick! Just as an FYI, the only other thing I suspect may have caused this strange behavior was the fact that the pop-up window, triggered by the showcatalogsearch() function, is a Telerik RadWindow, and the RadWindowManager's properties may have had a part to play in this Wagnerian tragedy.
Anyway, I cannot thank you enough for your time and help! I owe you one.... Cheers!
benmess
Member
4 Points
2 Posts
Re: Using Javascript to set TextBox Value, embedded within a user control.
Jul 20, 2009 12:35 AM|LINK
We have the same problems with several telerik controls. I could get it to update the value if I took out the client side events. Not ideal of course because then you cannot detect client side changes. So we have gone down the same path as you and ditched the telerik radTextBox in favour of a standard ASP text box. More than a bit annoying.
LLahman
Member
38 Points
40 Posts
Re: Using Javascript to set TextBox Value, embedded within a user control.
Nov 03, 2009 03:52 PM|LINK
I have just finished working through this issue myself, although without the benefit of Telerik's support staff. The final resolution that I discovered did not match up with Telerik suggestions or their documentation. Obviously this reflects poorly on Telerik to some extent, but I think it is more indicative of an environment which includes .NET 2.0, .NET 3.5, JavaScript, AJAX, Master Pages and is quickly becoming more complicated than it needs to be. When properties in Javascript are different from properties in code behind from properties in Javascript with Master Pages, etc. then I think we are headed off the cliff -- if not today, then certainly tomorrow. Anyway, here is the solution I discovered:
function OnClientClose(oWnd, args) { //get the transferred arguments var arg = args.get_argument(); if (arg) { var cityName = arg.cityName; var seldate = arg.selDate; var screenName; screenName = document.getElementById("<%= MyScreenName.ClientID %>"); screenName.value = cityName; screenName.set_displayvalue = cityName; var a1; var a2; a1 = document.getElementById("<%= MyScreenName.ClientID %>" + "_text"); a1.value = cityName; } }There is a certain lack of conceptual integrity in the variable names, etc. I apologize for that but this is a work in progress that started from a Telerik example.
The most notable factors are:
(1) cityname and seldate are variables on the RadWindow child;
(2) MyScreenName is a RadTextBox on the parent window;
(3) You must get addressability to the "generic" RadTextBox AND to the "_text" variant and set both of these values for the overall solution to work properly.
(4) The "generic" RadTextBox value is the actual internal, programmatic value of the control.
(5) The "_text" value is the displayed value of the control.
If I am not being clear, feel free to ask questions and I'll do my best to answer them.