ラベル onload の投稿を表示しています。 すべての投稿を表示
ラベル onload の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

ResizableControlExtender OnClientResize firing onload :-(

I have a ResizableControlExtender on my page. I set the OnClientResize to a js function with an alert. When I load the page, the alert pops. As expected, the alert pops on resize too, but I don't want the js function to be called on load. Is this a bug or expected behavior?

Thanks,

figz

Anyone?

To clarify (since it was Friday afternoon when I wrote the original post)...

Here is my ResizableControlExtender:

<ajaxToolkit:ResizableControlExtender ID="rceWrapper" runat="server" TargetControlID="panWrapper" HandleCssClass="handleWrapper"
MaximumHeight="0" MinimumWidth="960" BehaviorID="rceWrapper" OnClientResize="sayHello" />

Here is my js:

function sayHello(){alert('hello');}

The problem is when I load the page, the alert pops up. I would expect this to ONLY happen OnClientResize. So the question is, is this a bug or expected behavior? Thanks!


Hi Figz,

As far as I know, when the ResizableControlExtender control be initialized , it will call its _resizeControl(x, y, width,height) function. So that caused your problem.

To resolve this problem , my solution is to use a flag which will be set to true at pageLoad event. Just like this:

<script type="text/javascript" language="javascript">
var flag = false;
function pageLoad(){
flag = true;
}
function OnClientResizeText(sender, eventArgs) {
if(flag){
//your code;
}
}

</script>

Now , only when the flag is true , alert is allowed to be executed.

Another solution is attaching your javascript function on pageLoad event instead of defining as the ResizableControlExtender's property. Just like this.

<script type="text/javascript" language="javascript">
function pageLoad(){
$find('ResizableControlBehaviorID').add_resizing(OnClientResizeText)
}
function OnClientResizeText(sender, eventArgs) {
}

</script>

I hope this help.

Best regards,

Jonathan


Success! Thanks so much! For the record, I used the second option of attaching the js function on pageLoad instead of declaring it as a property. It worked like a charm!

Resizing the Ajax ResizableControlExtender durning the OnLoad event

I'm having a problem with the Ajax ResizableControlExtender.

The control is around an asp panel, which is around a gridview. The gridview is really wide, and I need the headers to stay at the top when scrolling down. That's working just fine.

I have a body onresize javascript event that resizes the ResizableControlExtender to fit better on the screen whenever the screen is resized.

What I need to do is have the resize event fire on the "OnLoad" event.

But at that time the ResizableControlExtender has not been initialized (or so I suppose) and is undefined at that time.

Is there a way to resize the ResizableControlExtender to the current window size in the page load event?

Thanks.

Chuck Snyder

Hi Chuck,

Based on my understanding, the pageLoad method is fired after all extenders on the page have been initialized. But if it doesn't work with you, please try to use window.setTimeout method to invoke the resize method in pageLoad, so that it will be called asynchronized at later.

For instance:

function pageLoad() { window.setTimeout(resize, 1000); }