Вы находитесь на странице: 1из 2

================================================================================

adding .dll file into asp.net project and custom validator for checkbox list
================================================================================

>>>how to make .dll in asp.net+c#


-===============-------------------------------
1.start visual studio
2.select new project ----> class library
3.type u'r code and press build. u'll find .dll in bin folder of u'r project
folder.
4.place in bin folder of the project

---------------------------------------------
example code in class library:::
--------------------------------------------
using system;
using system.web.ui;
using system.web.ui.webcontrols;
using system.componentmodel;

namespace customvalidators
{
public class requiredfieldvalidatorforcheckboxlists :
system.web.ui.webcontrols.basevalidator
{
private listcontrol _listctrl;

public requiredfieldvalidatorforcheckboxlists()
{
base.enableclientscript = false;
}

protected override bool controlpropertiesvalid()


{
control ctrl = findcontrol(controltovalidate);

if (ctrl != null)
{
_listctrl = (listcontrol) ctrl;
return (_listctrl != null);
}
else
return false; // raise exception
}

protected override bool evaluateisvalid()


{
return _listctrl.selectedindex != -1;
}
}
}

0.press build and find .dll in bin folder


1. place .dll file into bin folder
2. now add it like user control with assembly ="name of .dll file" u placed in
bin.
3. your page ----->
<%@ register tagprefix="customvalidators" namespace="customvalidators"
assembly="customvalidators" %>

<%@ register tagprefix="customvalidators" namespace="customvalidators"


assembly="customvalidators" %>
<html>

<script language="c#" runat="server">

function btnsubmit_click(sender as object, e as eventargs)


if page.isvalid then
response.write("<i>you have selected at least one checkbox!</i>")
end if
end

</script>

<body>
<form runat="server">
<asp:checkboxlist id="cblist" runat="server">
<asp:listitem value="hello" />
<asp:listitem value="world!" />
</asp:checkboxlist>

<customvalidators:requiredfieldvalidatorforcheckboxlists
id="reqcblist" runat="server" controltovalidate="cblist"
errormessage="please select at least one checkbox..." />

<asp:button id="button1" runat="server" text="button" />


</form>
</body>
</html>

Вам также может понравиться