How to redirect if there was no querystring key && value?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandub
    New Member
    • Oct 2010
    • 2

    #1

    How to redirect if there was no querystring key && value?

    Hi friends,

    this is my problem

    i have a link like this .

    http://www.mysite.com/product-detail.aspx?pro ductid=1

    its fine with the above link

    but if we delete the querystring part page should be redirected.

    http://www.mysite.com/product-detail.aspx (after deleting the querystring)

    Awaiting your help.

    Thanks in advance.
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    Hello Chandub,

    There are a few ways of accomplishing what you are trying to do. I will give you one example.

    product-detail.aspx
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="product-detail.aspx.vb" Inherits="product_detail" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head runat="server">
            <title></title>
        </head>
        <body>
            <form id="form1" runat="server">
            </form>
        </body>
    </html>
    product-detail.aspx.vb
    Code:
    Partial Class product_detail
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If (Request.QueryString("productid") = Nothing) Then
                Response.Redirect("product-detail.aspx")
            Else
                form1.InnerHtml = "Value in querystring is:" & Request.QueryString("productid").ToString
            End If
        End Sub
    End Class
    Happy Coding,
    CroCrew~

    Comment

    • Sameer Peter

      #3
      There Can be possibility of by default in product-detail.aspx page there would be something populated on the basis of productid.So plz check it .

      Comment

      • chandub
        New Member
        • Oct 2010
        • 2

        #4
        Hi crocrew

        Thank you very much for your help. i'll try that.

        Comment

        Working...