Hi guys
I've got a development question? I've setup a user control (
ascx) on one of my pages for generating a new user account. In my control I have three dropdownlists for the administrator of the system to select from when generating the account. Each dropdownlist is linked to a different sql datasource, i.e. Role, UserType and Service.
The problem I have is at runtime I get "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control". As far as I can see there should be no problem binding the dropdownlist to the sql datasources at runtime but I still receive this error.
Has anyone else experienced the same issue?
Code:
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="NewUser.ascx.vb" Inherits="ExistingUser" %>
<style type="text/css">
.style1
{
width: 900px;
}
.InputBox
{
width: 300px;
}
.Button
{
font-family: Tahoma;
color: #6e6e6e;
width: 95px;
}
.style4
{
height: 20px;
}
.style5
{
width: 400px;
}
</style>
<table class="style1" runat="server" id="FormTable">
<tr>
<td class="style4">
Please enter a
User
Name</td>
<td class="style5">
<asp:TextBox ID="NewUserNameTextBox" ToolTip="Please enter a User Name" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style4">
Please enter a
Password</td>
<td class="style5">
<asp:TextBox ID="NewPasswordTextBox" ToolTip="Please enter a Password" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="NewPasswordTextBox" CssClass="ErrorMessage" Display="Dynamic"
ErrorMessage="Enter a valid password">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="style4">
Please verify the Password</td>
<td class="style5">
<asp:TextBox ID="NewPasswordVerifyTextBox"
ToolTip="Please verify the Password" runat="server" ></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="NewPasswordVerifyTextBox" CssClass="ErrorMessage"
Display="Dynamic" ErrorMessage="Confirm a valid password">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server"
ControlToCompare="NewPasswordTextBox" ControlToValidate="NewPasswordVerifyTextBox"
CssClass="ErrorMessage" Display="Dynamic" ErrorMessage="Retype the password">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td class="style4">
Please enter an
E-mail Address</td>
<td class="style5">
<asp:TextBox ID="NewEmailAddressTextBox" ToolTip="Please enter an Email Address" runat="server"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="NewEmailAddressTextBox" CssClass="ErrorMessage" Display="Dynamic"
ErrorMessage="Enter a valid e-mail address">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="NewEmailAddressTextBox" CssClass="ErrorMessage"
Display="Dynamic" ErrorMessage="Enter a valid e-mail address" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style4">
Please verify an E-mail Address</td>
<td class="style5">
<asp:TextBox ID="NewEmailAddressVerifyTextBox"
ToolTip="Please verify the Email Address" runat="server" ></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="NewEmailAddressVerifyTextBox" CssClass="ErrorMessage"
Display="Dynamic" ErrorMessage="Confirm a valid e-mail address">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="NewPasswordTextBox" ControlToValidate="NewPasswordVerifyTextBox" CssClass="ErrorMessage" Display="Dynamic"
ErrorMessage="Retype the e-mail address">*</asp:CompareValidator>
</td>
</tr>
<tr>
<td class="style4">
Please select a
Role Type</td>
<td class="style5">
<asp:DropDownList ID="RoleDropDownList" runat="server"
DataSourceID="SqlDataSourceRoleNew" DataTextField="RoleType"
DataValueField="RoleType" SelectedIndex='<%#Bind("RoleID")%>'>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style4">
Please select a
User Type</td>
<td class="style5">
<asp:DropDownList ID="UserTypeDropDownList" runat="server"
DataSourceID="SqlDataSourceUserTypeNew" DataTextField="UserTypeDescription"
DataValueField="UserTypeDescription"
SelectedIndex='<%#Bind("UserTypeID")%>'>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style4">
Please select
Service Location</td>
<td class="style5">
<asp:DropDownList ID="ServiceDropDownList" runat="server"
DataSourceID="SqlDataSourceServiceNew" DataTextField="ServiceDescription"
DataValueField="ServiceDescription" SelectedIndex='<%#Bind("ServiceID")%>'>
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style4" colspan="3">
<asp:ValidationSummary ID="ValidationSummary" runat="server" CssClass="ErrorMessage" HeaderText="Please correct the following errors before creating the user account"
ShowMessageBox="True" ShowSummary="False" />
</td>
</tr>
</table>
<asp:SqlDataSource ID="SqlDataSourceRoleNew" runat="server"
ConnectionString="<%$ ConnectionStrings:LiteratureCataloguingConnectionString %>"
SelectCommand="SELECT DISTINCT RoleType, RoleID FROM Roles ORDER BY RoleType"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceUserTypeNew" runat="server"
ConnectionString="<%$ ConnectionStrings:LiteratureCataloguingConnectionString %>"
SelectCommand="SELECT DISTINCT UserTypeID, UserTypeDescription FROM UserType ORDER BY UserTypeDescription"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSourceServiceNew" runat="server"
ConnectionString="<%$ ConnectionStrings:LiteratureCataloguingConnectionString %>"
SelectCommand="SELECT DISTINCT ServiceID, ServiceDescription FROM Service ORDER BY ServiceDescription"></asp:SqlDataSource>
<script src="../Scripts/jquery.updnWatermark.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$.updnWatermark.attachAll({ cssClass: 'Watermark' });
});
</script>