How to get values from RowEditTemplate

Answered (Not Verified) This post has 0 verified answers | 19 Replies | 4 Followers Thread's RSS feed.

davefevold
Points 1,005
Replied On: Tue, Apr 19 2011 6:32 PM Reply

How do you get/set values from RowEditTemplate during onTemplateClosed client event using javascript? can someone share code with me? Thanks!

  • Post Points: 35

All Replies

AgentD5
Points 33,384
Answered (Not Verified) Replied On: Wed, Apr 20 2011 9:07 AM Reply
Suggested by AgentD5

Hi davefevold,

By the time that the TemplateClosed event fires, the values will already have been carried to the row's cells.  So you could check those cells.  The row is available off of the event args.  If you wanted to do validation to prevent the template closing, use the TemplateClosing event, then you'd have to find the objects using $get(id), $find(id), or document.getElementById(id) calls.  Similar to what we do internally.

regards,

David Young

  • Post Points: 5
Replied On: Thu, Apr 21 2011 5:50 AM Reply

Hello davefevold,

Let us know if you need further assistance after the provided by David suggestion.

Kind Regards,

Tsvetelina Georgieva

Infragistics, Inc.

  • Post Points: 20
davefevold
Points 1,005
Replied On: Thu, Apr 21 2011 9:26 AM Reply

I've tried the following code to retieve values from a textbox on the RowEdit Template but it doesn't work...what am I doing wrong?

 function onTemplateClosing(sender, e) {
     var grid = sender;
     var ret = grid.get_behaviors().get_editingCore().get_behaviors().get_rowEditingTemplate();
     var oInstrumentNbr = ret.$get({"Instrument_No"}).value;
}

  • Post Points: 20
AgentD5
Points 33,384
Answered (Not Verified) Replied On: Thu, Apr 21 2011 11:01 AM Reply

Hi Dave,

That code is wrong.  You would use $get on its own.

var oInstrumentNbr = $get("Instrument_No").value;  But, the id has to be the whole client id, since asp.net will give it a name containing parent ids.  Or if you are using CLR 4, you could try setting id to static.  Another option is to search through the child nodes of the ret template div.  This can be found off of the ret behavior as ret._templateDiv.  Then start searching childNodes collection to find your editors.  But these will be straight html elements.  If you have any of our controls, you'd be better off trying to find them with $find(id).  You just need the client id.  Hope this helps you out.

-Dave

  • Post Points: 20
davefevold
Points 1,005
Replied On: Thu, Apr 21 2011 3:52 PM Reply

Can you give me a full javascript coding example for getting the value of a WebDatePicker from a RowEditTemplate during the TemplateClosing client event? 

  • Post Points: 20
AgentD5
Points 33,384
Replied On: Thu, Apr 21 2011 4:03 PM Reply

Hi,

Here is is.

function templateClosing(sender, args)

        {

            var ret = sender.get_behaviors().get_editingCore().get_behaviors().get_rowEditingTemplate();

            var colKey = "BirthDate";

            var binding = ret._bindings._getObjectByAdr(colKey);

            var datePicker = $find(binding.get_clientID());

            var dateVal = datePicker.get_value();

        }

-Dave

  • Post Points: 35
davefevold
Points 1,005
Replied On: Thu, Apr 21 2011 4:16 PM Reply

Great...thanks!!!

  • Post Points: 5
davefevold
Points 1,005
Replied On: Thu, Apr 21 2011 5:32 PM Reply

If I wanted to check and then set the date value would I then do the following?

function templateClosing(sender, args)

        {

            var ret = sender.get_behaviors().get_editingCore().get_behaviors().get_rowEditingTemplate();

            var colKey = "BirthDate";

            var binding = ret._bindings._getObjectByAdr(colKey);

            var datePicker = $find(binding.get_clientID());

            var dateVal = datePicker.get_value();

if (dateVal == null) {

datePicker.set_value('12/31/9999')

}

        }

  • Post Points: 20
AgentD5
Points 33,384
Replied On: Fri, Apr 22 2011 8:55 AM Reply

Hi,

I would think that would work, so long as the date picker will return you null for the date if it is not set.

-Dave

  • Post Points: 20
davefevold
Points 1,005
Replied On: Mon, Apr 25 2011 9:46 AM Reply

After using the the same code, the date was null and I still received the following error:

{"String was not recognized as a valid DateTime."}

Any other ideas on how to replace the null date?

Thanks!

  • Post Points: 5
davefevold
Points 1,005
Replied On: Mon, Apr 25 2011 2:09 PM Reply

When I try to replace the date's null value with the below code, it does not change the date's value when reaching the wdgSecIns_RowUpdating Sub.

 

 

 

 

 

var 

 

colKey3 = "Canceled_Date";

 

 

var binding3 = ret._bindings._getObjectByAdr(colKey3);

 

 

var datePicker3 = $find(binding3.get_clientID());

 

 

var Canceled_Date = datePicker3.get_value();

 

 

 

if (Canceled_Date == null) {

datePicker3.set_value(

"12/31/9999");

 

 

 

 

 

 

 

}

  • Post Points: 20
AgentD5
Points 33,384
Replied On: Mon, Apr 25 2011 2:50 PM Reply

Hi,

I'm not intimately familar with the WebDatePicker, however when I look at the source code, it appears that it expects a Date object for set_value(), whereas you are passing a string.  That could be the source of your problem.  Try that and let me know.

thanks,
Dave 

  • Post Points: 20
davefevold
Points 1,005
Replied On: Mon, Apr 25 2011 3:25 PM Reply

Dave, it doesn't matter what I put in the set_value() for the date object...I still get the error message. If I have all date fields filled in for the RowEditTemplate, once I press the ok button, the ret closes fine and proceeds to the WebDataGrid_RowUpdating sub. If there is a date field not filled in or null, when I press the ok button, I get the error message and it never proceeds to the WebDataGrid_RowUpdating sub. That is why I'm trying to catch it and change the date before it blows up.  Thanks for any help you can provide!

  • Post Points: 5
davefevold
Points 1,005
Replied On: Mon, Apr 25 2011 4:00 PM Reply

Dave, I found my issue...I had the my client event defined wrong, as follows. I was trying to change the values after the template had closed already...thx for your help.

TemplateClosed

 

="onTemplateClosing"

  • Post Points: 5
Page 1 of 2 (20 items) 1 2 Next > | RSS