Chuck,
I think you've raised very valid points (and yes, you did a great job
at it !)
m...@ni,
Some of the points raised by Chuck echo what I teach my team (when I
lecture them on coding practices)... In short, there is no error
condition that is to be left unchecked and nothing is to be assumed.
Your two line code snippet has (atleast) the following flaws :
1. The Request.QueryString() returns a string object (if the key
exists) so calling ToString() on it is useless.
2. The Request.QueryString() returns null (if the key doesn't exist)
so calling ToString() will raise an NRE exception.
3. You get a string from the Request.QueryString, then convert it to
an int, then append it to a string again. This is also useless.
4. int.Parse will throw a FormatException when your Querystring value
is blank. int.TryParse is universally considered a better method.
In other words, your code assumes that there will always be a
querystring parameter named CngID and it will always have a value.
Here is how I would have done it :
---
string cngID = Request.QueryString["CngId"];
if(!string.IsNullOrEmpty(cngID))
{
HYPViewCng.NavigateUrl = "~/Admin/CngSection/ViewCng.aspx?CngId="
+ cngID;
}
else
{
// Log error or handle appropriately.
}
---
Of course, this is assuming that you are using .NET 2.0 or greater.
Either way, don't be discouraged. I'm just trying to help you learn
and I think Chuck had the same intention.
On Dec 30, 12:36 am, Chuck <[email protected]> wrote:
> Technically, from what I see here, you have it setup correctly (unless
> I missed something here). However, I have a few questions:
>
> - The page that has this code, does it have the parameter labeled
> "Cngld" in the url?
> - If it does have the parameter, is it blank, null, or listed as ""?
> - Is the new page pulling the parameter you're sending across and
> retrieving your information? What is the error you're getting?
>
> I ask you this because if you have your current url listed as "http://
> indexCNG.aspx", getting a Request.QueryString of any kind will give
> you an error, as there is no parameter on the current link. This
> will mess you up because you can't pass "CngId" since it doesn't
> exist.
>
> If your current url is listed as "http://indexCNG.aspx?CngId=" where
> CngId doesn't equal anything, youre request.querystring is going to
> pass a blank (or is it null) value to new link.
>
> Assuming you're using C#, I would do the following for starters:
>
> 1) I would make sure that the current url has a reference to CngID
> before you even attempt to get a request.queryString. If you don't,
> none of the following, let alone the rest of your code, will work, as
> CngID will not exist.
>
> 2) I would then make sure you're getting a valid result when you're
> pulling a request.querystring for starters. Example? On your code
> behind, throw a response.write(hypviewcng.navigateUrl) or something to
> see what the result is.
>
> 3) I would also click on the link and see if it gets the value you're
> expecting into the url. If the displayed URL isn't what you were
> intending to show, then you know you didn't set it up right either.
>
> Once you're done, you should be able to pull your query on the new
> page and get your information.
>
> Hopefully, this gets you started. �...@ni, let me know if this helps or
> if I misunderstood your statement. Cerebrus, if I've missed something
> or messed this up, let me know too. LOL
>
> On Dec 29, 9:55 am, "m...@ni" <[email protected]> wrote:
>
>
>
> > Hi Cerebrus how ru??
>
> > Thanks for showing concern,actualy i just want to use the value of
> > querystring in hyperlink control,and that hyperlink control is placed
> > on html side,actualy after using my aesthetic sense i came up with
> > this solution.
>
> > ___On Html Side.___
> > <asp:HyperLink ID="HYPViewCng" Target="_blank" runat="server" >View
> > Cngs</asp:HyperLink> .
>
> > ___On Code Behind___
> > int CngId = int.Parse(Request.QueryString["CngId"].ToString()); .
> > HYPViewCng.NavigateUrl = "~/Admin/CngSection/ViewCng.aspx?CngId=" +
> > CngId;
>
> > Thanks for suporting me alot, i realy apreciate ur responses.Thanks
> > Alot................- Hide quoted text -
>
> - Show quoted text -