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

Calling client side JavaScript function after Telerik RadPageView finishes loading

1 Answer 331 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rohhan
Top achievements
Rank 1
Rohhan asked on 12 Sep 2015, 01:25 AM

m using Telerik UI for asp.net. Specifically I'm using RadTabStrip with partial page postbacks to allow the user to tab through different sets of data. When the user clicks a tab, some code executes and loads data just for that tab.

 

Some things I've tried that work for similar problems:

I've figured out how to execute codebehind: I set the OnTabClick property of the RadTabStrip, and then in codebehind I check what tab was clicked.
E.g.

protected void tab_Click(object sender, RadTabStripEventArgs e)

if (e.Tab.Text == "Info")

    { populateInfoTab();

}

private void populateInfotab()

{

    // Do some stuff

}

 

However, I can't figure out how to execute client side javascript after a specific tab is clicked. What I tried:
Set OnClientTabSelected property, and then add some javascript:

function tab_ClientClick(sender, args)

{

    var tab = args.get_tab();

    if(tab.get_text() == "Info")

    {

       alert("Tab Clicked");

    }

}

This works, BUT:  

The problem is that I need to set the InnerHtml of some div in the clicked pageview after it is clicked. I cannot do:

   some_div.InnerHtml = "test";

after the alert.

The div does not exist on page load (that specific RadPageView is hidden) so I cannot set it then. Once the user clicks into the tab, and after the page view loads, I need to be able to update the div's InnerHtml through JavaScript.
How would I go about doing this?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 16 Sep 2015, 12:07 PM
Hello,

The text set to a div in a PageView not appearing after a postback/partial postback is expected. You can workaround this behavior by adding a HiddenField control on your page, which will hold the text value and you can use it to set the div's text after the page has loaded following a Tab click. You can do this the following way:
  • Set the text to the HiddenField's Value property in the OnClientTabSelecting or OnClientTabSelected event handler: $("#HiddenField1").val("New text");
  • Subscribe to the TabStrip's OnClientLoad event. It will fire after the TabStrip is loaded. Get the HiddenField value in its handler, set it to the div and set the HiddenField's value to an empty string:
function OnClientLoad(sender) {
    if ($("#HiddenField1").val() != "") {
        $(".pageView2Div").text($("#HiddenField1").val());
        $("#HiddenField1").val("");
    }
}

Regards,
Ivan Danchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Rohhan
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or