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

Radgrid and Toolbar Inheritance

1 Answer 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 19 Oct 2010, 12:27 PM

 

Hi,

I’ve been working on a Custom Radgrid and Radtoolbar control which works very well.  At the moment the javascript used is still in the design view of the page and want to include this in my control dll. I’ve looked around the site and can’t find any examples of how to go about doing this.

 

How would I go about including the below in my code:

function RowClick(sender, eventArgs) {

            if (editedRow != null && hasChanges) {

                if (confirm("Update changes?")) {

                    hasChanges = false;

                    $find("<%=gvGrid.MasterTableView.ClientID %>").updateItem(editedRow);

                }

                else {

                    hasChanges = false;

                }

            }

        }

 

Also how would I change it so gvGrid is dynamic so I can have different names for my grids etc.

 

Any pointers in the right direction would be great.

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 22 Oct 2010, 02:18 PM
Hello Karl,

There are plenty of approaches for loading client scripts from your server control dynamically. The simplest is to hard-code the script appending the ClientID of the MasterTableView from inside the control:

private string rowClickScript = "function RowClick(sender, eventArgs) { if (editedRow != null && hasChanges) { if (confirm('Update changes?')) { hasChanges = false; $find('" + this.MasterTableView.ClientID + "').updateItem(editedRow); } else { hasChanges = false; } } }";

Then you can add this script to the page together with your server control:

protected override void Render(HtmlTextWriter writer)
{
    // render your control
    writer.Write("<script>" + rowClickScript + "/<script>");
}

However, a more flexible and conforming approach would be to make add this script in to a .js file in your assembly and load it as a script resource. Here is more info on ASP.NET AJAX script control development:

MSDN: Adding client capabilities to a web server control

You do not necessarily need to implement a client-side component for your control, but you include its scripts in the way depicted in the article.

Regards,
Veli
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
Tags
General Discussions
Asked by
Karl
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or