PDA

View Full Version : [CLOSED] How to use js funtion to hide the button?



hujq
Mar 16, 2013, 3:43 PM
hi all:
I need to use a js fuction to hide or show my button , i try many ways to do this,but still fail!please help me!

the failure ways as example:


var CheckSetRight = function CheckSetRight(rightstr) {
var int = rightstr.substring(0, 1);
var upd = rightstr.substring(1, 2);
var del = rightstr.substring(2, 3);
Ext.Msg.alert('', int + upd + del);
if (int == '0') {
App.btnInsert.disable();
//document.getElementById("btnInsert").style.display = "none";
}
else if (upd == '0') {
Ext.getCmp('btnUpdate').disable();
//document.getElementById("btnUpdate").style.display = "none";
}
else if (del == '0') {
Ext.getCmp('btnDelete').disable();
// document.getElementById("btnDelete").style.display = "none";
}

geoffrey.mcgill
Mar 16, 2013, 11:54 PM
You should be able to just call .hide() on the Button instance.

Example


App.btnUpdate.hide();

Hope this helps.

hujq
Mar 17, 2013, 4:32 AM
You should be able to just call .hide() on the Button instance.

Example


App.btnUpdate.hide();

Hope this helps.


I can hide the button using the App.btnUpdate.hide() when the page load completely ,but now ,i want to hide the button when the page is loading, I bind the function which contain the App.btnUpdate.hide() code,the code is as flow:


<body onload="CheckSetRight('000')">

<script type="text/javascript" language="javascript">
var CheckSetRight = function CheckSetRight(rightstr) {


var int = rightstr.substring(0, 1);
var upd = rightstr.substring(1, 2);
var del = rightstr.substring(2, 3);

if (int == '0') {
App.btnInsert.hide();
}
else if (upd == '0') {

}
else if (del == '0') {

}



};



</script>

5837

please help me!!!

Daniil
Mar 18, 2013, 8:02 AM
Hi @hujq,

A body's onload handler is too early to access components via the application's namespace ("App" by default).

There are a few options.

1. Set up a Button's BeforeRender listeners, check the conditions inside and set up a Button's hidden property to true if needed.

Example

<ext:Button runat="server" Text="Button">
<Listeners>
<BeforeRender Handler="if (true) {
this.hidden = true;
}" />
</Listeners>
</ext:Button>

2. Call your function within a ResourceManager's DocumentReady listener. You might need to check the "rendered" flag.

Example

If (btn.rendered) {
btn.hide();
} else {
btn.hidden = true;
}

3. If appropriate it can be done on server side. Sure, if you know the conditions of server. Then just set a Button's Hidden property to true in, for example, a Page_Load handler.

hujq
Mar 19, 2013, 2:13 AM
Thanks very much,i have solve my problem using your method which you provided yesterday!




Hi @hujq,

A body's onload handler is too early to access components via the application's namespace ("App" by default).

There are a few options.

1. Set up a Button's BeforeRender listeners, check the conditions inside and set up a Button's hidden property to true if needed.

Example

<ext:Button runat="server" Text="Button">
<Listeners>
<BeforeRender Handler="if (true) {
this.hidden = true;
}" />
</Listeners>
</ext:Button>

2. Call your function within a ResourceManager's DocumentReady listener. You might need to check the "rendered" flag.

Example

If (btn.rendered) {
btn.hide();
} else {
btn.hidden = true;
}

3. If appropriate it can be done on server side. Sure, if you know the conditions of server. Then just set a Button's Hidden property to true in, for example, a Page_Load handler.

hujq
Mar 19, 2013, 3:01 AM
hi all:

I have solve the problem successfully by your providered method.thanks!


Hi @hujq,

A body's onload handler is too early to access components via the application's namespace ("App" by default).

There are a few options.

1. Set up a Button's BeforeRender listeners, check the conditions inside and set up a Button's hidden property to true if needed.

Example

<ext:Button runat="server" Text="Button">
<Listeners>
<BeforeRender Handler="if (true) {
this.hidden = true;
}" />
</Listeners>
</ext:Button>

2. Call your function within a ResourceManager's DocumentReady listener. You might need to check the "rendered" flag.

Example

If (btn.rendered) {
btn.hide();
} else {
btn.hidden = true;
}

3. If appropriate it can be done on server side. Sure, if you know the conditions of server. Then just set a Button's Hidden property to true in, for example, a Page_Load handler.