简体   繁体   中英

How to use response.redirect from aspx in vb.net?

function temp() {
        <% Response.Redirect("TS.aspx?PPStartDate="+HttpUtility.UrlEncode(hdnPP.Value),true)%>
    }

<img alt="" class="style1" src="../Asps/Images/calendar.gif"   önclick="temp();" />

I'm calling this function on button onclick event from aspx which isn't working. Please share your ideas.

You can't do that!!!

You are trying to mix server-side code and client-side code.

The stuff in the <% %> will be executed as the HTML response is being constructed. The redirect will occur before the client even sees the HTML!

Instead, keep the whole thing on the client:

function temp() {
    location.href = "TS.aspx?PPStartDate=" + UrlEncode(hdnPP.Value);
}

Note that I'm not quite certain of the syntax for the JavaScript equivalent of UrlEncode, or whether hdnPP.Value will work the way you have your code written.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM