Post by bfr on Nov 28, 2005 21:07:14 GMT -5
The following example demonstrates the use of asp.net controls and dropdown list validation. It is availible for open testing here.
If you view the source (View > Source on IE), you get a bunch of almost jiberish-looking javascript and stuff. All of this was generated by the server. When you view the source, it should look something like:
The actual code for the page is much shorter (without the ads, but it's still much shorter):
Kind of neat, eh?
If you click "OK" on the page when the selected item says "Pick A Color", you get a message saying "Whoops! You forgot to choose a color!
".
Again, like all of my examples, I'd be happy to explain anything you all don't understand and I'd be happy to answer your questions.
If you view the source (View > Source on IE), you get a bunch of almost jiberish-looking javascript and stuff. All of this was generated by the server. When you view the source, it should look something like:
<html>
<body>
<form name="_ctl0" method="post" action="form.aspx" language="javascript" onsubmit="if (!ValidatorOnSubmit()) return false;" id="_ctl0">
<input type="hidden" name="__VIEWSTATE" value="dDwxODQzODA4MjkxOzs+gWKNF/V5juyzojfpG3rSUT2/XN8=" />
<script language="javascript" type="text/javascript" src="/aspnet_client/system_web/1_1_4322/WebUIValidation.js"></script>
What Color Do You Prefer?<br>
<select name="Color" id="Color">
<option selected="selected" value="Pick A Color">Pick A Color</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<span id="ColorRequired" controltovalidate="Color" isvalid="False" evaluationfunction="RequiredFieldValidatorEvaluateIsValid" initialvalue="Pick A Color" style="color:Red;">
Whoops! You forgot to choose a color!
</span><br>
<input type="submit" name="OK" value="OK" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " language="javascript" id="OK" />
<script language="javascript" type="text/javascript">
<!--
var Page_Validators = new Array(document.all["ColorRequired"]);
// -->
</script>
<script language="javascript" type="text/javascript">
<!--
var Page_ValidationActive = false;
if (typeof(clientInformation) != "undefined" && clientInformation.appName.indexOf("Explorer") != -1) {
if ((typeof(Page_ValidationVer) != "undefined") && (Page_ValidationVer == "125"))
ValidatorOnLoad();
}
function ValidatorOnSubmit() {
if (Page_ValidationActive) {
return ValidatorCommonOnSubmit();
}
return true;
}
// -->
</script>
</form>
</body>
</html><!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->
</noscript></object></layer></style></title></xml></applet>
<script language="javascript">
var Ssac = false;var Ssc = false;
function Ss_sec(){Ssc = false;}
function S_ssac(){Ssac = true;}
function D_ssac(){Ssac = false;}
function Do_se(){if (Ssac&&!Ssc) {Ssc = true;setTimeout("Ss_sec()",10000);S_tst(""); i=0; for (i=0;i<1000000;i++) {j=i;}}if (sEmpty!=null) sEmpty();}
function S_tst(SomeeCT) {
Mu="somee.com/admin/ProcessAdClick.aspx";Md=document; Mnv=navigator; Mp=0; Md.cookie="b=b"; Mc=0; if(Md.cookie)Mc=1; Mrn=Math.random();
Mn=(Mnv.appName.substring(0,2)=="Mi")?0:1; Mz="p="+Mp+"&rn="+Mrn+"&c="+Mc; if(self!=top){Mfr=1;}else{Mfr=0;}
My="http://"+Mu+"?cid=someehost&ct="+SomeeCT+"&"+Mz+"&vr=adwords&r="+escape(Md.referrer)+"&fr="+Mfr+"&pg="+escape(window.location.href)+"&go="+escape(window.status);
//window.open(My);
smeimg=new Image();smeimg.src=My;
}
function sEmpty(){}
sEmpty=window.onbeforeunload;window.onbeforeunload=Do_se;
</script><script language="JavaScript" src="http://ads.mgmt.somee.com/serveimages/layerad1/adscrpt1.js"></script>
<div id="y_gc_div_adcntr" style="visibility:visible;background-color:#FFFFFF;margin:0px;padding:0px;z-index:31000;top:0px;float:right;width:195px;text-align:left;">
<div id="y_gc_div_mast" style="border:1px solid; width: 195px;visibility: visible;background-color: #FFFFFF;position: absolute;z-index: 31001;top: 0px">
<a href="http://somee.com"><img src="http://ads.mgmt.somee.com/serveimages/layerad1/someehosting1.gif" alt="Somee Web Hosting" width="140" height="15" hspace="4" vspace="4" border="0"></a><img src="http://ads.mgmt.somee.com/serveimages/layerad1/space.gif" width="7" height="1"><a href="javascript:;" onMouseDown="maximizeAu('y_gc_div_au1');" ;><img src="http://ads.mgmt.somee.com/serveimages/layerad1/arrowsdown.gif" width="14" height="13" hspace="2" vspace="6" border="0"></a><a href="javascript:;" onClick="closeAu('y_gc_div_adcntr');" ;><img src="http://ads.mgmt.somee.com/serveimages/layerad1/closebtn.gif" width="14" height="13" hspace="2" vspace="6" border="0"></a></div>
<div id="y_gc_div_au1" style="border:1px solid;padding:0px;background-color:#FFFFFF;visibility:visible;width:195;margin:0px;position:absolute;z-index:31002;top:0px">
<a href="http://somee.com">
<img src="http://ads.mgmt.somee.com/serveimages/layerad1/SomeeHosting1.gif" alt="Somee Web Hosting" width="140" height="15" hspace="4" vspace="4" border="0"></a><img src="http://ads.mgmt.somee.com/serveimages/layerad1/space.gif" width="7" height="1"><a href="javascript:;" onMouseDown="minimizeAu('y_gc_div_au1');" ;><img src="http://ads.mgmt.somee.com/serveimages/layerad1/arrowsup.gif" width="14" height="13" hspace="2" vspace="6" border="0"></a><a href="javascript:;" onClick="closeAu('y_gc_div_adcntr');";><img src="http://ads.mgmt.somee.com/serveimages/layerad1/closebtn.gif" width="14" height="13" hspace="2" vspace="6" border="0"></a>
<div id="ctr12" onmouseover="S_ssac();" onmouseout="D_ssac();" style="background-color:#FFFFFF;z-index:31000;border-top-width:1px;border-top-style:solid;border-top-color: #CCCCCC;margin:0px;padding:0px;width:195px;">
<IFRAME id="someeCover" style="LEFT:0;POSITION:absolute;TOP:0;z-index:-1" src="" frameBorder="0" scrolling="no" width="195" height="401"></IFRAME>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="193" id="AutoNumber2" height="23"> <tr><td width="11" height="3"></td><td width="179" height="3"></td></tr><tr>
<td width="11" height="19"> </td><td width="179" height="19">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="160" id="AutoNumber1" height="370">
<tr>
<td width="100%" valign="top">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2" height="44">
<tr>
<td width="100%" align="left" height="17"><font face="Arial Black">
<a href="http://somee.com/"><font color="#808080" style="font-size: 12">
Somee.com</font></a></font></td>
</tr>
<tr>
<td width="100%" height="8"></td>
</tr>
<tr>
<td width="100%" height="19">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="57">
<tr>
<td width="100%" height="15">
<font face="Arial" style="font-size: 12; font-weight:700" color="#990033">
Advanced hosting plan</font></td>
</tr>
<tr>
<td width="100%" height="6"></td>
</tr>
<tr>
<td width="100%" height="19">
<font face="Tahoma" style="font-size: 11">250MB Web Space <br>
5GB Web Traffic <br>
15 Domains/Sub Domains<br>
ASP & ASP.NET Support<br>
FTP Access <br>
MS Access databases <br>
5 E-Mail accounts<br>
No advertising</font></td>
</tr>
<tr>
<td width="100%" height="36">
<font face="Arial Black" style="font-size: 12" color="#0000FF">
<a href="http://somee.com/PlanFeatures.aspx?PlanID=3">
<font color="#333399">Only $4.95/Month</font></a></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%" height="19"> </td>
</tr>
<tr>
<td width="100%" height="19">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3" height="56">
<tr>
<td width="100%" height="15">
<font face="Arial" style="font-size: 12; font-weight:700" color="#990033">
Free hosting plan</font></td>
</tr>
<tr>
<td width="100%" height="6"></td>
</tr>
<tr>
<td width="100%" height="19">
<font face="Tahoma" style="font-size: 11">105MB Web Space <br>
2GB Web Traffic <br>
ASP & ASP.NET Support<br>
FTP Access <br>
MS Access databases </font></td>
</tr>
<tr>
<td width="100%" height="35">
<a href="http://somee.com/FreePackage.aspx">
<font face="Arial Black" style="font-size: 12" color="#333399">
Absolutely free!</font></a></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table> </td></tr></table>
</div></div></div>
<script language="javascript">if(!checkFrame()){closeAu('y_gc_div_au1');}else{S_tst("h")};someeObj=document.getElementById("y_gc_div_adcntr").parentElement;while(someeObj!=null){someeObj.style.display='inline';someeObj=someeObj.parentElement;}</script>
<!--SCRIPT GENERATED BY SERVER! PLEASE REMOVE-->
The actual code for the page is much shorter (without the ads, but it's still much shorter):
<%@Page Explicit="True" Language="VB" Debug="True" %>
<html>
<body>
<form runat="server">
What Color Do You Prefer?<br>
<asp:dropdownlist id="Color" runat="server">
<asp:listitem>Pick A Color</asp:listitem>
<asp:listitem>Red</asp:listitem>
<asp:listitem>Green</asp:listitem>
<asp:listitem>Blue</asp:listitem>
</asp:dropdownlist>
<asp:requiredfieldvalidator id="ColorRequired" controltovalidate="Color" runat="server" initialvalue="Pick A Color">
Whoops! You forgot to choose a color!
</asp:requiredfieldvalidator><br>
<asp:button id="OK" text="OK" runat="server" />
</form>
</body>
</html>
Kind of neat, eh?
If you click "OK" on the page when the selected item says "Pick A Color", you get a message saying "Whoops! You forgot to choose a color!
".
Again, like all of my examples, I'd be happy to explain anything you all don't understand and I'd be happy to answer your questions.