c# - Stop executing code when return null on Page_load -
i have page has few properties in .cs, properties later on used in .aspx instance:
.cs
public string person { get;set; }
.aspx
<a href="<%= person.website %> >my website</a>
the problem here if person null, framework still try run .aspx , end throwing null-exception.. , if make simple check in page_load
if(person == null) return
it still try execute .aspx, again throw exception
so.. question is.. there anyway prevent .aspx getting loaded if persons null
if(person == null) //dont run aspx,code response.write("something went wrong!");
thanks in advance!
first, can write code :
<a href="<%= person != null? person.website : null %> >my website</a>
but results in producing unclickable link. propably not desired, isn't it?
but such requirements far more easier fulfill using databinding. asp.net has been design mimic windows forms behavior. doing here, "legacy" asp code-style, writing in html stream. there case when it's legitimate, it's not usual.