views:

33

answers:

2

I am trying to use response.redirect on a button click event server side but it gives me http 400 bad request error. I was not getting this error before but I just moved the projectto vs 2010 framework 4.0 and I started getting this error. This is what I am writing:

 protected void bOrganizationAddID_Click(object sender, EventArgs e)
    {
        string MyURL;
        MyURL = "addNewPopup.aspx?orgID=" + this.OrganizationID;

        Response.Redirect(MyURL);



    }

and when i try to build it, the url shown on the page with error is : http://localhost:2504/padrap/pages/admin/%2fpadrap%2fpages%2fadmin%2faddNewPopup.aspx%3forgID%3d33

instead of being just: localhost:2504/padrap/pages/admin/addNewPopup.aspx?orgID=33

Can anyone help me out here please. How do I get the redirect to take me to the correct url? Thanks!

+1  A: 

try-- Server.UrlEncode(this.OrganizationID)

pjb
nope... same error..
Ratan
A: 

So, I think this is a bug in 4.0 or something, as I tried everything. The workaround is this though:

ScriptManager.RegisterStartupScript(this, this.GetType(), 
           "redirectFixOrg", string.Format("document.location = '{0}?orgID={1}'",
           this.ResolveClientUrl("~/pages/admin/addNewPopup.aspx"), this.OrganizationID), true);

This worked for me but I dont know why response.redirect is not working.

Thanks!

Ratan