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

Get position of a control inside a "Nested" RadGrid

4 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 16 Apr 2015, 02:46 PM

Hello,

I have a RadGrid (Grid A) and inside it's NestedViewTemplate I have another RadGrid (Grid B).  Within "Grid B" I have a GridTemplateColumn that contains a RadButton.  I'm trying to figure out how to get the position of this button in JavaScript/jQuery when the user clicks on it (OnClientClicked event) so that I can display and position a hovering <div> or <asp:panel>.

 I've tried using syntax such as the one below to find the button and then use jQuery's "position()", then set the CSS properties for the div, but "button" is not visible to JavaScript code because it's inside the nested Grid.: 

var element = $find('<%= button.ClientID %>');

 Can anyone help me figure out how to do this?

 Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 20 Apr 2015, 12:22 PM
Hello Shawn,

You can pass reference to the button control to the OnClientClick handler. Check out the following code snippet that illustrates the approach.

<asp:Button Text="click" runat="server" ID="Button1" OnClientClick="clientClick(this, event); return false;" />


JavaScript:

function clientClick(sender, args) {
    var button = $(sender);
 
    alert(button.position().top);
}


Regards,
Viktor Tachev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Shawn
Top achievements
Rank 1
answered on 20 Apr 2015, 12:48 PM

Hello Viktor,

Thanks!  This code works with a regular ASP button; however when I use it in the OnClientClicking or OnClientClicked events of a RadButton I get a JavaScript error stating: "JavaScript critical error in (unknown source location)\n\nSCRIPT1009: Expected '}'".

I'm not sure why I'm getting this error.  I'd really like to use the RadButton since it offers a lot more options.

Could this be due to having a RadAjaxManagerProxy and having both RadGrids ajaxified?  Thanks.

0
Viktor Tachev
Telerik team
answered on 21 Apr 2015, 02:14 PM
Hi Shawn,

In order to use RadButton you can modify the code like shown below:

Markup:

<telerik:RadButton Text="click" runat="server" ID="Button1" OnClientClicked="clientClick" AutoPostBack="false" />

JavaScript:

function clientClick(sender, args) {
    var button = $(sender.get_element());
 
    alert(button.position().top);
 
}

Let me know how the approach works for you.

Regards,
Viktor Tachev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Shawn
Top achievements
Rank 1
answered on 21 Apr 2015, 02:19 PM

Hello Viktor,

Thanks for your reply.  This is good to know for the future, but I ended up using an asp ImageButton and your previous solution worked for me for what I wanted to do.

Thanks for your help!

Tags
Grid
Asked by
Shawn
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Shawn
Top achievements
Rank 1
Share this question
or