Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I made a page Default.aspx which contains category of books.It contains a edit link. On clicking edit button, it redirects the user to edit.aspx , But i send the id through querystring like edit.aspx?id=5.
Suppose, if user change the id like edit.aspx?id=abc , it gives exception.
Plz help me how to handle the query string.
Posted

u can do one thing u can encode the url or u can use exception handling
 
Share this answer
 
Hi Try like this.



C#
protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               string value = Request.QueryString["id"];
               int id = 0;
               if (int.TryParse(value, out id))
               {
                   // value is valid
               }
               else
               {
                   Response.Write("Please dont modify the URL :) ");
               }
           }


       }


You can also try by Encode/Decode the url..

refer : http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900