Pergunta

I'm almost sure I've done this before, but I can't find it anywhere...

I have 3 tabs in an ajax TabContainer and 2 CheckBoxes outside. All 3 tabs are visible unless both the CheckBoxes are unchecked, in which case the 3rd tab should be hidden.

I can show/hide in javascript when the checkbox values are changed

    $find('<%=OptionsTabs.ClientID%>').get_tabs()[2]._hide();
    $find('<%=OptionsTabs.ClientID%>').get_tabs()[2]._show();

but on PageLoad, I can't get it to work with C#. I tried setting display and visibility, but neither hid the tab. The only thing that worked was setting Visible=false, but if I do that the tab isn't rendered at all and the javascript can't show it later.

EDIT: I tried registering the same script in PageLoad, but still doesn't work

    string script = "<script type=text/javascript> $find('<%=OptionsTabs.ClientID%>').get_tabs()[2]._hide(); </script>";

    ClientScriptManager cs = Page.ClientScript;
    String csname1 = "TabScript";
    Type cstype = this.GetType();
    cs.RegisterStartupScript(cstype, csname1, script);

OptionsTabs is null here.

I tried sending the ClientID I get server side. I tried sending the tab name instead of the tabcontainer name. I tried setting the display/visibility of the tab and tab header. Nothing worked.

Foi útil?

Solução

Try this code:

string script = "$find('" + OptionsTabs.ClientID + "').get_tabs()[2]._hide();";
ClientScriptManager cs = Page.ClientScript;
String csname1 = "TabScript";
Type cstype = this.GetType();
cs.RegisterStartupScript(cstype, csname1, script, true);

As an alternative, since you're using MS Ajax and it has page lifecycle for client-side as well you can try Load event in JavaScript, add this to clinet-side code:

Sys.Application.add_load(appLoaded);

function appLoaded(sender, eventArgs) {
   $find('<%=OptionsTabs.ClientID%>').get_tabs()[2]._hide();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top