How to change the QueryString on post back?
I would like to perform a post back and ha开发者_如何学Gove several values added to my query string. I had been using a redirect to the same URL and simply adding query string parameters but when I do this my View State is cleared, which I need to avoid.
Because of the technology I am working with (SharePoint) I have to pass my parameters using the query string.
I did some looking around, but haven't found an clear answer on how to accomplish a post back with different query string parameters. Is there any way to do this?
Just messing around, but this adds querystrings clientside by modifing the action attribute of the main form (in this case ct101), before the form gets submitted. Sample code doesnt take futher postbacks into account..
<script type="text/javascript">
var el = document.getElementById('ctl01');
el.onsubmit = function (evt) {
var url = $(this).attr('action');
$(this).attr('action', url + '?sayHi=Hi');
};
</script>
Try to use Server.Transfer instead of Response.Redirect. The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.
So basically you can transfer to the same page but with newly added query string parameters you will still have access to the old values.
精彩评论