This is a migrated thread and some comments may be shown as answers.

Javascript label updates in RadWindow do not show in code behind

2 Answers 125 Views
Window
This is a migrated thread and some comments may be shown as answers.
Blake
Top achievements
Rank 1
Blake asked on 01 Mar 2012, 12:15 AM
I am using the RadWindow as a dialog for updating some user notes on my database.  I have the RadWindow defined on my main page.  When the user clicks a button, I open the RadWindow and set several field values on the window using Javascript.  The user then enters their data and clicks a "Submit" button.

In the code behind, I am getting the data from the fields on the RadWindow and then calling my database update routine.  The issue I am having is this.  When I pop the window up using Javascript, I am modifying some label, RadTextbox, and Radbutton control text values.  In the code behind I need to use the values. The text values are fine but the labels that I change in the Javascript do not have the updated values in the code behind.  Does anybody know why?

I am using the "OnClientShow" event to call the Javascript routine to modify the RadWindow fields.  Here is the routine:

// This function moves the data from various fields in the carrierinformation page to the data
// update request screen being opened. Some of the fields are actual data fields from the screen
// while others are hidden fields.
function SetDataUpdWindowFields() {
    // Get Carrier name and set.
    var CarrName = GetCarrierName();
    var DUCarrName = document.getElementById("<%= lblDataUpdCarrName.ClientID %>");
    DUCarrName.innerText = CarrName;
    // Get Email Address and Set.
    var EmailAddr = document.getElementById("<%= hfEmailAddr.ClientID %>");
    var DUEmailAddr = $find("<%= rtxtDataUpdEmailAdr.ClientID %>");
    DUEmailAddr.set_value(EmailAddr.value);
    // Set the user notify option to yes.
    $find("<%= roptDataUpdNotifyYes.ClientID %>").set_checked(true);
    $find("<%= roptDataUpdNotifyNo.ClientID %>").set_checked(false);
    // Get and set the location name.
    var rpageview = GetCurrPageView();
    if (rpageview) {
        var lblLocName = $telerik.$(".cdhdr-carrlocationheader", rpageview._element).html();
        if (lblLocName) {
            var DULocName = document.getElementById("<%= lblDataUpdLocName.ClientID %>");
            DULocName.innerText = lblLocName;
        }
    }
}

It is specifically the DUCarrName and DULocName values on the RadWindow that show correctly on the actual window, but do not have the new values in the code behind.

Any help would be greatly appreciated.

Blake

2 Answers, 1 is accepted

Sort by
0
Accepted
Marin Bratanov
Telerik team
answered on 02 Mar 2012, 11:36 AM
Hi Blake,

A label renders as a span and does not retain its value across postbacks. This is just the way the control works. You can easily confirm it in the simple page I am attaching here. More information about this is also available in the net, e.g. this page. What I can suggest as a simple workaround is to use hidden fields and populate their values as well for use in the code-behind. You can also search the net for other ideas.


All the best,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Blake
Top achievements
Rank 1
answered on 02 Mar 2012, 04:53 PM
Thanks Marin.  I figured it was something like that.  I got around the problem by swapping out the labels for textboxes and setting them to read only with no border. 

Thanks again.

Blake
Tags
Window
Asked by
Blake
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Blake
Top achievements
Rank 1
Share this question
or