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!

0 件のコメント:

コメントを投稿