开发者

HTML - How to hide postbacks?

开发者 https://www.devze.com 2022-12-25 07:01 出处:网络
Can someone let me know the technique 开发者_Python百科used to \'hide\' postback when pressing a button?If you want to stop the page from refreshing, you can use an UpdatePanel in the Ajax Control Too

Can someone let me know the technique 开发者_Python百科used to 'hide' postback when pressing a button?


If you want to stop the page from refreshing, you can use an UpdatePanel in the Ajax Control Toolkit. This lets you refresh only a portion of the page, and it is impossible to tell just from looking at it.


Ajax is likely the solution you really want, but there is a quick and dirty solution to what you want to do (if I've understood you correctly). You can put a hidden iframe in your html with a name, let's say:

<iframe name='hidden-result'...

You can set the target of the form you are submitting to go to the iframe like:

<form target='hidden-result'... 

Just make sure you hide the iframe and nobody will be the wiser. Of course, if you actually want to do something with the response it gets a little trickier ;)


Actually, one way I've found to hide postbacks in IE is to use page transitions with a very short interval:

<meta http-equiv="Page-Enter" content="blendTrans(Duration=.01)" />
<meta http-equiv="Page-Exit" content="blendTrans(Duration=.01)" />

This causes the page to literally flip from one screen to another by adding a blend transition that is very short.

In other browsers, you could do the following:

<SCRIPT type="text/javascript">

function fadeInit() {
document.body.style.opacity=0.2; // initialise
}

function fadeIn() {

var bodyStyle=document.body.style;

if ( bodyStyle.opacity < 1) {
bodyStyle.opacity=((bodyStyle.opacity*10)+1)/10; //Add 0.1
setTimeout('fadeIn();',50)
}
}

</SCRIPT>

<body onload="fadeInit();fadeIn();">

Credit for the second script here: http://www.secretgeek.net/fajax.asp


It is unclear what exactly you're asking as the term "postback" is misplaced in the context of your question. That's also why I asked in a comment to elaborate a bit more about it in your own words.

After all, I suspect that you just like to block the button's default action (submitting the form) when pressing the button and executing some JavaScript code attached to the event. If this is true, then all you need to do is to let the event return false.

Basic kickoff example:

<input type="submit" value="submit" onclick="doStuff(); return false;">

or if doStuff() itself already returns true or false, e.g. validateForm(this) or so, so that you can decide whether to proceed with the form submit, then do so:

<input type="submit" value="submit" onclick="return doStuff();">

To handle this more clean and unobtrisuvely I'd suggest to have a look at jQuery.


Depending on what you mean by 'hiding postbacks', Post-redirect-get is a common pattern that may solve your problem.

The basic idea is that you redirect after processing each POST, so that clients only receive pages produced by GET commands. Among other things, this keeps clients from accidentally double-posting when they hit the refresh button.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号