views:

138

answers:

4

hi

i have a web for and want to 'get' it to another page.. is there anyway to submit it without posting the viewstate and other bits i dont want? or should i be catching the submit button click and redirecting with a querystring i build myself

thanks

A: 

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.

Kangkan
Why not disable the ViewState at the Page level so? You can do it on Page directive or on the PageInit event.
Carlos Loth
Yes, that will be a better approach. Thanks @carlos.
Kangkan
+1  A: 

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.

Filip Ekberg
A: 

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" />
Carlos Loth
hithanks yes this was my initial thought.. just felt a bit like there may be a way to deal with this automatically.. as mentioned in another answer maybe jquery get would be a nice option as it would avoid a trip to the server
nat
And that requires viewstate....
leppie
@Carlos, that would require 2 transfers / calls to the server which causes overhead.
Filip Ekberg
dont care if it uses the viewstate or not really, just dont want it in the QS, or the eventvalidation and other associated cr*p just the fields that have been selected in some way..
nat
@Filip I know that. The question didn't mentioned any concern about doing more than one round trip to the server.
Carlos Loth
@Carlos, why would you ever want to do that? It's bad design.
Filip Ekberg
@Filip Please show me an example of a good design, so I can learn how it looks like.
Carlos Loth
A: 

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.

leppie