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

Popup Edit Form & JQuery

5 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Philip Senechal
Top achievements
Rank 1
Philip Senechal asked on 30 Aug 2010, 08:16 PM
Hello,

I could use a little assistance here. I have a grid that I'm using popup edit forms to add new records and edit existing ones. On the popup edit form, I have 2 RadTextBoxes that I want to use a JQuery script for to count the characters entered and show the remaining available.

So...I need a way to fire off a client side event and get the client ID of those two RadTextBoxes so I can put them in the JQuery.

The JQuery script is a simple one liner that uses the client ID of the textbox to get the object and then writes the results using a span ID.

Is there a way to use the OnPopUpShowing client side event to get the client ID of those RadTextBoxes? Do I have to do it in the ItemCreated event on the server side and register the JavaScript?

Any help you can provide is much appreciated. Thanks.

5 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 02 Sep 2010, 12:20 PM
Hi Philip,

You can try handling the OnKeyPress client-side event of the RadTextBox controls. There the sender would be the client object of the control.

Check it out and let me know if any issues arise.

All the best,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Philip Senechal
Top achievements
Rank 1
answered on 02 Sep 2010, 05:00 PM
If I tied it to the onkeypress event, it wouldn't give me the total characters remaining when the form loads...only if someone actually typed in the box. The JQuery script needs to execute on load.

I'm thinking I can use the OnItemCreated event and check for an EditFormItem...I'll just need to register a startup script in that event to launch the JavaScript with the client ID of the RadTextBox. I'll give it a shot and see what I can come up with.
0
Philip Senechal
Top achievements
Rank 1
answered on 02 Sep 2010, 06:26 PM
I guess I still need a little help.

If I want to inject a JavaScript to run from the code-behind when the popup-edit form appears, which event should I use? ItemCreated, ItemDataBound, or a different one?

Should I enclose the script in a IF statement...if (e.item is GridEditFormItem && e.Item.IsInEditMode)?

Which method should I use? ClientScript.RegisterStartupScript or ClientScript.RegisterClientScriptBlock or a different one?

Any help you can provide is appreciated. Thanks.
0
Iana Tsolova
Telerik team
answered on 03 Sep 2010, 08:27 AM
Hi Philip,

Firstly I need to mention that the RadInput has OnLoad client-side event as well, which you might use in this case.
Otherwise you can register the sript either on ItemCreated or ItemDataBound and you need the preceding if statement. I would suggest that you use the ScriptManager.RegisterStartupScript() static method.

Best wishes,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Philip Senechal
Top achievements
Rank 1
answered on 03 Sep 2010, 07:35 PM
Thank you for the great information!

I realized that it's just not going to work from the server-side. I read too many articles talking about launching JQuery events from server-side and how the document.ready() function just doesn't fire correctly.

So...I used your suggesting for the OnLoad client-side event which I didn't know existed. I always look for events in the tag itself, so I was looking for a OnClientLoad event for the RadTextBox and couldn't find it. I didn't realized after opening the tag, there was a sub-tag for ClientEvents.

I was able to get my JQuery function to run using sender.get_id() and appending '_text' to the variable. The JQuery function runs, but the character count doesn't update until a character is pressed. I'm thinking this is something I can fix in the JQuery script to pass the current text and subtract it from the max allowed.

By the way...if anyone is looking for a great character counter in JQuery, I highly recommend NobleCount!

Thanks again for the assistance!
Tags
Grid
Asked by
Philip Senechal
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Philip Senechal
Top achievements
Rank 1
Share this question
or