I have a web form and want to 'get' it to another page..
is there anyway to submit it without posting the ViewState
and other bits I don't want?
Or should I be catching the submit button click and redirecting with a querystring I build myself.
I have a web form and want to 'get' it to another page..
is there anyway to submit it without posting the ViewState
and other bits I don't want?
Or should I be catching the submit button click and redirecting with a querystring I build myself.
You have a couple of options here:
You don't have to disable ViewState on all pages, just the pages that you do not care for the state to be saved.
But there is also the option to disable the ViewState completely if you never want to use it.
If you just want to compose a GET by yourself, you can use jQuery for that aswell so you only pass the parameters you really want which will give you 100% control of what is posted /getted.
If you are not using the viewstate
, why have you kept it enabled? Just disable it. For every server control, set the EnableViewState = False
and you are free from it. If you need the viewstate
, it will be part of the post all the time.
There are different ways to persist viewstate.
I have had in the past, had to persist viewstate on the server (using ApplicationState/Session, cant remember) for a heavy AJAX page to support faster updates. Works well.
See Page.LoadPageStateFromPersistenceMedium
and Page.SavePageStateToPersistenceMedium
.
Sorry, no links from Reflector available.
You could add an event handler to your search button and do something similar to this
private void button_Click(object sender, EventArgs e)
{
String query = queryTextBox.Text;
Response.Redirect("SearchResults.aspx?query=" + query);
}
Using JavaScript
function doSearch()
{
// Assuming you are not using jQuery,
// using jQuery it would be $('#queryTextBox').value instead
var queryString = document.getElementById('queryTextBox').value;
window.open("SearchResults.aspx?query=" + queryString);
return false;
}
Html
<input type="text" id="queryTextBox" />
<input type="button" onclick="return doSearch()" value="Go" />