Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Can't visible property of DropDownList in FormView control

Reply
Thread Tools

Can't visible property of DropDownList in FormView control

 
 
Hollywood
Guest
Posts: n/a
 
      02-07-2008
I have a formview control that contains a dropdownlist (nested in a
panel) and I want to set the visible property to False when the user
is in a particular role. I'm using a modal popup button click event
to fire the change, and I set the formview mode to Insert and that
works great. Just after that I try to set the dropdownlist.visible =
false (or true depending) and I can find the control okay but it never
sets the visibility.

I've been chasing after this for a couple of days and any help would
really be appreciated!!



Here's the code:

aspx page:

<asp:FormView ID="FormView1" runat="server" DataSourceID="Dealer"
Width="27%">
<InsertItemTemplate>
<table id="InsertItemTable" runat="server" style="width: 656px">
<tr>
<td style="width: 703px">
<aspanel ID="InsertDealerInfoPanel" runat="server"
GroupingText="Dealer Info" Width="700px">
<table id="InsertDealerInfoTable" runat="server"
style="width: 672px">
<tr>
<td style="width: 138px">
OGC ID:
</td>
<td style="width: 214px">
<asp:Label ID="OGCIDLabel" runat="server" Text='New'></
asp:Label>
</td>
</tr>
<tr>
<td style="width: 138px">
Contact Name:</td>
<td style="width: 214px">
<asp:TextBox ID="NameTextBox" runat="server" Text='<%#
Bind("Name") %>' Width="300px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="NameTextBox"
Display="Dynamic" ErrorMessage="Contact Name is reqired."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 138px">
Company Name:</td>
<td style="width: 214px">
<asp:TextBox ID="CompanyTextBox" runat="server" Text='<%#
Bind("Company") %>' Width="300px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 138px">
Company Type:</td>
<td style="width: 214px">
<asp:RadioButton ID="CorporationRadioBtn" runat="server"
GroupName="BusinessType" Text="Corporation" />&nbsp;&nbsp;
<asp:RadioButton ID="NonCorporationRadioBtn"
runat="server" GroupName="BusinessType" Text="Non-Corporate Entity" /
>&nbsp;

<asp:TextBox ID="Is1099TextBox" runat="server" Text='<%#
Eval("Is_1099") %>' Visible="False"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 138px; height: 26px;">
Phone:</td>
<td style="width: 214px; height: 26px;">
<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%#
Bind("Phone") %>' Width="152px" MaxLength="10"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4"
runat="server" ControlToValidate="PhoneTextBox"
Display="Dynamic" ErrorMessage="Phone is required."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 138px">
Fax:</td>
<td style="width: 214px">
<asp:TextBox ID="FaxTextBox" runat="server" Text='<%#
Eval("FaxNumber") %>' Width="152px" MaxLength="10"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 138px">
Cell Phone:</td>
<td style="width: 214px">
<asp:TextBox ID="CellPhoneTextBox" runat="server" Text='<
%# Eval("CellPhone") %>' Width="152px" MaxLength="10"></asp:TextBox></
td>
</tr>
<tr>
<td style="width: 138px">
Email Address:</td>
<td style="width: 214px">
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%#
Eval("EmailAddress") %>' Width="300px"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator5"
runat="server" ControlToValidate="EmailTextBox"
Display="Dynamic" ErrorMessage="Email Address is
required." ValidationGroup="Insert"></
asp:RequiredFieldValidator><asp:RegularExpressionV alidator
ID="RegularExpressionValidator1" runat="server"
ControlToValidate="EmailTextBox"
Display="Dynamic" ErrorMessage="You must enter a valid
email address." Width="296px" ValidationExpression="\w+([-+.']\w+)*@\w+
([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
</tr>
<tr>
<td style="width: 138px">
Tax ID or Social Security:</td>
<td style="width: 214px">
<asp:TextBox ID="TaxIDTextBox" runat="server" Text='<%#
Eval("TaxID") %>' Width="152px" MaxLength="9"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator6"
runat="server" ControlToValidate="TaxIDTextBox"
Display="Dynamic" ErrorMessage="Please enter a valid
Federal Tax ID or SS Number." ValidationGroup="Insert" Width="376px"></
asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 138px;
height: 26px">
User ID:</td>
<td style="width: 214px;
height: 26px">
<asp:TextBox
ID="UserIDTextBox" runat="server"></asp:TextBox><br />

<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ControlToValidate="UserIDTextBox"
Display="Dynamic"
ErrorMessage="User ID is a required field."></
asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 138px">
Password:</td>
<td style="width: 214px">
<asp:TextBox
ID="PwdTextBox" runat="server" TextMode="Password"></asp:TextBox>
<br />

<asp:RequiredFieldValidator ID="RequiredFieldValidator3"
runat="server" ControlToValidate="PwdTextBox"
Display="Dynamic"
ErrorMessage="Password is a required field."></
asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 138px;
height: 26px;">
Confirm Password:</td>
<td style="width: 214px;
height: 26px;">
<asp:TextBox
ID="ConfirmPwdTextBox" runat="server" TextMode="Password"></
asp:TextBox><br />

<asp:RequiredFieldValidator ID="RequiredFieldValidator8"
runat="server" ControlToValidate="ConfirmPwdTextBox"
Display="Dynamic"
ErrorMessage="Confirm Password is a required field."></
asp:RequiredFieldValidator><br />
<asp:CompareValidator
ID="CompareValidator1" runat="server" ControlToCompare="PwdTextBox"

ControlToValidate="ConfirmPwdTextBox" Display="Dynamic"
ErrorMessage="Password and Confirm Password do not match."></
asp:CompareValidator></td>
</tr>
</table>
</aspanel>
</td>
</tr>
<tr>
<td style="width: 703px">
<aspanel ID="InsertDealerAddressPanel" runat="server"
GroupingText="Address" Width="700px">
<table id="InsertDealerAddressTable" runat="server"
style="width: 672px">
<tr>
<td style="width: 125px">
Address:</td>
<td style="width: 214px">
<asp:TextBox ID="Address1TextBox" runat="server" Text='<%#
Bind("Address1") %>' Width="300px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7"
runat="server" ControlToValidate="Address1TextBox"
Display="Dynamic" ErrorMessage="Address is required."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 125px; height: 26px;">
</td>
<td style="width: 214px; height: 26px;">
<asp:TextBox ID="Address2TextBox" runat="server" Text='<%#
Bind("Address2") %>' Width="300px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 125px">
City:</td>
<td style="width: 214px">
<asp:TextBox ID="CityTextBox" runat="server" Text='<%#
Bind("City") %>' Width="176px" MaxLength="25"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator11"
runat="server" ControlToValidate="CityTextBox"
Display="Dynamic" ErrorMessage="City is required."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 125px; height: 26px;">
State/Province:</td>
<td style="width: 214px; height: 26px;">
<aspropDownList ID="StateDropDown" runat="server"
DataSourceID="SqlDataSource1" DataTextField="description"
DataValueField="state" Width="176px">
<asp:ListItem
Selected="True"></asp:ListItem>
</aspropDownList><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator10"
runat="server" ControlToValidate="StateDropDown"
Display="Dynamic" ErrorMessage="Please choose a state."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 125px; height: 45px;">
Postal Code:</td>
<td style="width: 214px; height: 45px;">
<asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<
%# Bind("PostalCode") %>' Width="176px" MaxLength="10"></
asp:TextBox><br />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator9" runat="server"
ControlToValidate="PostalCodeTextBox" Display="Dynamic"
ErrorMessage="Postal Code is required."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 125px">
Country:</td>
<td style="width: 214px">
<aspropDownList ID="CountryDropDown" runat="server"
Width="176px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>United States</asp:ListItem>
<asp:ListItem>Canada</asp:ListItem>
</aspropDownList>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator12"
runat="server" ControlToValidate="CountryDropDown"
Display="Dynamic" ErrorMessage="Please choose a Country."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
</table>
</aspanel>
</td>
</tr>
<tr>
<td style="width: 703px">
<aspanel ID="InsertDealerAccountPanel" runat="server"
GroupingText="Bank Account" Width="700px">
<table id="InsertDealerAccountTable" runat="server"
style="width: 672px">
<tr>
<td style="width: 125px">
Account Number:</td>
<td style="width: 214px">
<asp:TextBox ID="AccountTextBox" runat="server"
Text='<%# Bind("Account") %>' Width="300px"
MaxLength="20"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator15"
runat="server" ControlToValidate="AccountTextBox"
Display="Dynamic" ErrorMessage="Account Number is
required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 125px">
Routing Number:</td>
<td style="width: 214px">
<asp:TextBox ID="RoutingNumberTextBox" runat="server"
Text='<%# Eval("RoutingNumber") %>' Width="176px" MaxLength="9"></
asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator16"
runat="server" ControlToValidate="RoutingNumberTextBox"
Display="Dynamic" ErrorMessage="Routing Number is
required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 125px">
Account Currency:</td>
<td style="width: 214px">
<aspropDownList ID="CurrencyDropDown" runat="server"
Width="96px">
<asp:ListItem Selected="True"></asp:ListItem>
<asp:ListItem>USD</asp:ListItem>
<asp:ListItem>CND</asp:ListItem>
</aspropDownList><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator17"
runat="server" ControlToValidate="CurrencyDropDown"
Display="Dynamic" ErrorMessage="Please select a currency
for the account." Width="288px" ValidationGroup="Insert"></
asp:RequiredFieldValidator></td>
</tr>
</table>
</aspanel>
</td>
</tr>
<tr>
<td style="width: 703px">
<aspanel ID="InsertDealerAdvancedPanel" runat="server"
GroupingText="Advanced" Width="700px">
<table id="InsertDealerAdvancedTable" runat="server"
style="width: 672px">
<tr>
<td style="width: 90px">
Salesman Level:</td>
<td style="width: 218px">
<aspropDownList ID="SalesmanLevelDropDown"
runat="server" Width="96px">
<asp:ListItem>Level 1</asp:ListItem>
<asp:ListItem>Level 2</asp:ListItem>
</aspropDownList></td>
</tr>
<tr>
<td style="width: 90px">
Territory Manager:</td>
<td style="width: 218px">
<aspropDownList ID="TerritoryMgrDropDown" runat="server"
DataSourceID="TMObjectDataSource" DataTextField="Name"
DataValueField="SalesmanID" Width="176px"
AutoPostBack="True">
</aspropDownList><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator14"
runat="server" ControlToValidate="TerritoryMgrDropDown"
Display="Dynamic" ErrorMessage="Please choose a TM."
ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
</tr>
</table>
</aspanel>
</td>
</tr>
</table>
</InsertItemTemplate>



Code behind:

Protected Sub ModalOkButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ModalOkButton.Click
Try


With Me.FormView1
.ChangeMode(FormViewMode.Insert)
.Visible = True
End With

With Me.TextBox1
.Text = ""
.Visible = False
End With

Me.SearchButton.Visible = False
Me.lnkInsertTop.Visible = True
Me.lnkInsertBottom.Visible = True
Me.lnkEditTop.Visible = False
Me.lnkEditBottom.Visible = False
Me.lnkUpdateTop.Visible = False
Me.lnkUpdateBottom.Visible = False
Me.lnkCancelTop.Visible = True
Me.lnkCancelBottom.Visible = True


Dim TMDropDown As DropDownList

TMDropDown =
Me.FormView1.FindControl("TerritoryMgrDropDown")

If UserInfo.IsInRole("TM") Then
TMDropDown.SelectedValue =
UserInfo.Profile.GetPropertyValue("SalesmanID")


Else
TMDropDown.Visible = True
End If
Trace.Write(TMDropDown.Visible.ToString)
Trace.Write(TMDropDown.SelectedValue.ToString)


Catch ex As Exception
Throw ex
End Try
End Sub

Thanks,
Hollywood
 
Reply With Quote
 
 
 
 
Hollywood
Guest
Posts: n/a
 
      02-07-2008
On Feb 7, 12:45 pm, Hollywood <(E-Mail Removed)> wrote:
> I have a formview control that contains a dropdownlist (nested in a
> panel) and I want to set the visible property to False when the user
> is in a particular role. I'm using a modal popup button click event
> to fire the change, and I set the formview mode to Insert and that
> works great. Just after that I try to set the dropdownlist.visible =
> false (or true depending) and I can find the control okay but it never
> sets the visibility.
>
> I've been chasing after this for a couple of days and any help would
> really be appreciated!!
>
> Here's the code:
>
> aspx page:
>
> <asp:FormView ID="FormView1" runat="server" DataSourceID="Dealer"
> Width="27%">
> <InsertItemTemplate>
> <table id="InsertItemTable" runat="server" style="width: 656px">
> <tr>
> <td style="width: 703px">
> <aspanel ID="InsertDealerInfoPanel" runat="server"
> GroupingText="Dealer Info" Width="700px">
> <table id="InsertDealerInfoTable" runat="server"
> style="width: 672px">
> <tr>
> <td style="width: 138px">
> OGC ID:
> </td>
> <td style="width: 214px">
> <asp:Label ID="OGCIDLabel" runat="server" Text='New'></
> asp:Label>
> </td>
> </tr>
> <tr>
> <td style="width: 138px">
> Contact Name:</td>
> <td style="width: 214px">
> <asp:TextBox ID="NameTextBox" runat="server" Text='<%#
> Bind("Name") %>' Width="300px"></asp:TextBox>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator1"
> runat="server" ControlToValidate="NameTextBox"
> Display="Dynamic" ErrorMessage="Contact Name is reqired."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 138px">
> Company Name:</td>
> <td style="width: 214px">
> <asp:TextBox ID="CompanyTextBox" runat="server" Text='<%#
> Bind("Company") %>' Width="300px"></asp:TextBox></td>
> </tr>
> <tr>
> <td style="width: 138px">
> Company Type:</td>
> <td style="width: 214px">
> <asp:RadioButton ID="CorporationRadioBtn" runat="server"
> GroupName="BusinessType" Text="Corporation" />&nbsp;&nbsp;
> <asp:RadioButton ID="NonCorporationRadioBtn"
> runat="server" GroupName="BusinessType" Text="Non-Corporate Entity" />&nbsp;
>
> <asp:TextBox ID="Is1099TextBox" runat="server" Text='<%#
> Eval("Is_1099") %>' Visible="False"></asp:TextBox></td>
> </tr>
> <tr>
> <td style="width: 138px; height: 26px;">
> Phone:</td>
> <td style="width: 214px; height: 26px;">
> <asp:TextBox ID="PhoneTextBox" runat="server" Text='<%#
> Bind("Phone") %>' Width="152px" MaxLength="10"></asp:TextBox>
> <br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator4"
> runat="server" ControlToValidate="PhoneTextBox"
> Display="Dynamic" ErrorMessage="Phone is required."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 138px">
> Fax:</td>
> <td style="width: 214px">
> <asp:TextBox ID="FaxTextBox" runat="server" Text='<%#
> Eval("FaxNumber") %>' Width="152px" MaxLength="10"></asp:TextBox></td>
> </tr>
> <tr>
> <td style="width: 138px">
> Cell Phone:</td>
> <td style="width: 214px">
> <asp:TextBox ID="CellPhoneTextBox" runat="server" Text='<
> %# Eval("CellPhone") %>' Width="152px" MaxLength="10"></asp:TextBox></
> td>
> </tr>
> <tr>
> <td style="width: 138px">
> Email Address:</td>
> <td style="width: 214px">
> <asp:TextBox ID="EmailTextBox" runat="server" Text='<%#
> Eval("EmailAddress") %>' Width="300px"></asp:TextBox><br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator5"
> runat="server" ControlToValidate="EmailTextBox"
> Display="Dynamic" ErrorMessage="Email Address is
> required." ValidationGroup="Insert"></
> asp:RequiredFieldValidator><asp:RegularExpressionV alidator
> ID="RegularExpressionValidator1" runat="server"
> ControlToValidate="EmailTextBox"
> Display="Dynamic" ErrorMessage="You must enter a valid
> email address." Width="296px" ValidationExpression="\w+([-+.']\w+)*@\w+
> ([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></td>
> </tr>
> <tr>
> <td style="width: 138px">
> Tax ID or Social Security:</td>
> <td style="width: 214px">
> <asp:TextBox ID="TaxIDTextBox" runat="server" Text='<%#
> Eval("TaxID") %>' Width="152px" MaxLength="9"></asp:TextBox>
> <br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator6"
> runat="server" ControlToValidate="TaxIDTextBox"
> Display="Dynamic" ErrorMessage="Please enter a valid
> Federal Tax ID or SS Number." ValidationGroup="Insert" Width="376px"></
> asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 138px;
> height: 26px">
> User ID:</td>
> <td style="width: 214px;
> height: 26px">
> <asp:TextBox
> ID="UserIDTextBox" runat="server"></asp:TextBox><br />
>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator2"
> runat="server" ControlToValidate="UserIDTextBox"
> Display="Dynamic"
> ErrorMessage="User ID is a required field."></
> asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 138px">
> Password:</td>
> <td style="width: 214px">
> <asp:TextBox
> ID="PwdTextBox" runat="server" TextMode="Password"></asp:TextBox>
> <br />
>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator3"
> runat="server" ControlToValidate="PwdTextBox"
> Display="Dynamic"
> ErrorMessage="Password is a required field."></
> asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 138px;
> height: 26px;">
> Confirm Password:</td>
> <td style="width: 214px;
> height: 26px;">
> <asp:TextBox
> ID="ConfirmPwdTextBox" runat="server" TextMode="Password"></
> asp:TextBox><br />
>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator8"
> runat="server" ControlToValidate="ConfirmPwdTextBox"
> Display="Dynamic"
> ErrorMessage="Confirm Password is a required field."></
> asp:RequiredFieldValidator><br />
> <asp:CompareValidator
> ID="CompareValidator1" runat="server" ControlToCompare="PwdTextBox"
>
> ControlToValidate="ConfirmPwdTextBox" Display="Dynamic"
> ErrorMessage="Password and Confirm Password do not match."></
> asp:CompareValidator></td>
> </tr>
> </table>
> </aspanel>
> </td>
> </tr>
> <tr>
> <td style="width: 703px">
> <aspanel ID="InsertDealerAddressPanel" runat="server"
> GroupingText="Address" Width="700px">
> <table id="InsertDealerAddressTable" runat="server"
> style="width: 672px">
> <tr>
> <td style="width: 125px">
> Address:</td>
> <td style="width: 214px">
> <asp:TextBox ID="Address1TextBox" runat="server" Text='<%#
> Bind("Address1") %>' Width="300px"></asp:TextBox>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator7"
> runat="server" ControlToValidate="Address1TextBox"
> Display="Dynamic" ErrorMessage="Address is required."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 125px; height: 26px;">
> </td>
> <td style="width: 214px; height: 26px;">
> <asp:TextBox ID="Address2TextBox" runat="server" Text='<%#
> Bind("Address2") %>' Width="300px"></asp:TextBox></td>
> </tr>
> <tr>
> <td style="width: 125px">
> City:</td>
> <td style="width: 214px">
> <asp:TextBox ID="CityTextBox" runat="server" Text='<%#
> Bind("City") %>' Width="176px" MaxLength="25"></asp:TextBox><br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator11"
> runat="server" ControlToValidate="CityTextBox"
> Display="Dynamic" ErrorMessage="City is required."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 125px; height: 26px;">
> State/Province:</td>
> <td style="width: 214px; height: 26px;">
> <aspropDownList ID="StateDropDown" runat="server"
> DataSourceID="SqlDataSource1" DataTextField="description"
> DataValueField="state" Width="176px">
> <asp:ListItem
> Selected="True"></asp:ListItem>
> </aspropDownList><br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator10"
> runat="server" ControlToValidate="StateDropDown"
> Display="Dynamic" ErrorMessage="Please choose a state."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 125px; height: 45px;">
> Postal Code:</td>
> <td style="width: 214px; height: 45px;">
> <asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<
> %# Bind("PostalCode") %>' Width="176px" MaxLength="10"></
> asp:TextBox><br />
> <asp:RequiredFieldValidator
> ID="RequiredFieldValidator9" runat="server"
> ControlToValidate="PostalCodeTextBox" Display="Dynamic"
> ErrorMessage="Postal Code is required."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 125px">
> Country:</td>
> <td style="width: 214px">
> <aspropDownList ID="CountryDropDown" runat="server"
> Width="176px">
> <asp:ListItem Selected="True"></asp:ListItem>
> <asp:ListItem>United States</asp:ListItem>
> <asp:ListItem>Canada</asp:ListItem>
> </aspropDownList>
> <br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator12"
> runat="server" ControlToValidate="CountryDropDown"
> Display="Dynamic" ErrorMessage="Please choose a Country."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> </table>
> </aspanel>
> </td>
> </tr>
> <tr>
> <td style="width: 703px">
> <aspanel ID="InsertDealerAccountPanel" runat="server"
> GroupingText="Bank Account" Width="700px">
> <table id="InsertDealerAccountTable" runat="server"
> style="width: 672px">
> <tr>
> <td style="width: 125px">
> Account Number:</td>
> <td style="width: 214px">
> <asp:TextBox ID="AccountTextBox" runat="server"
> Text='<%# Bind("Account") %>' Width="300px"
> MaxLength="20"></asp:TextBox>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator15"
> runat="server" ControlToValidate="AccountTextBox"
> Display="Dynamic" ErrorMessage="Account Number is
> required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 125px">
> Routing Number:</td>
> <td style="width: 214px">
> <asp:TextBox ID="RoutingNumberTextBox" runat="server"
> Text='<%# Eval("RoutingNumber") %>' Width="176px" MaxLength="9"></
> asp:TextBox>
> <asp:RequiredFieldValidator ID="RequiredFieldValidator16"
> runat="server" ControlToValidate="RoutingNumberTextBox"
> Display="Dynamic" ErrorMessage="Routing Number is
> required." ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> <tr>
> <td style="width: 125px">
> Account Currency:</td>
> <td style="width: 214px">
> <aspropDownList ID="CurrencyDropDown" runat="server"
> Width="96px">
> <asp:ListItem Selected="True"></asp:ListItem>
> <asp:ListItem>USD</asp:ListItem>
> <asp:ListItem>CND</asp:ListItem>
> </aspropDownList><br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator17"
> runat="server" ControlToValidate="CurrencyDropDown"
> Display="Dynamic" ErrorMessage="Please select a currency
> for the account." Width="288px" ValidationGroup="Insert"></
> asp:RequiredFieldValidator></td>
> </tr>
> </table>
> </aspanel>
> </td>
> </tr>
> <tr>
> <td style="width: 703px">
> <aspanel ID="InsertDealerAdvancedPanel" runat="server"
> GroupingText="Advanced" Width="700px">
> <table id="InsertDealerAdvancedTable" runat="server"
> style="width: 672px">
> <tr>
> <td style="width: 90px">
> Salesman Level:</td>
> <td style="width: 218px">
> <aspropDownList ID="SalesmanLevelDropDown"
> runat="server" Width="96px">
> <asp:ListItem>Level 1</asp:ListItem>
> <asp:ListItem>Level 2</asp:ListItem>
> </aspropDownList></td>
> </tr>
> <tr>
> <td style="width: 90px">
> Territory Manager:</td>
> <td style="width: 218px">
> <aspropDownList ID="TerritoryMgrDropDown" runat="server"
> DataSourceID="TMObjectDataSource" DataTextField="Name"
> DataValueField="SalesmanID" Width="176px"
> AutoPostBack="True">
> </aspropDownList><br />
> <asp:RequiredFieldValidator ID="RequiredFieldValidator14"
> runat="server" ControlToValidate="TerritoryMgrDropDown"
> Display="Dynamic" ErrorMessage="Please choose a TM."
> ValidationGroup="Insert"></asp:RequiredFieldValidator></td>
> </tr>
> </table>
> </aspanel>
> </td>
> </tr>
> </table>
> </InsertItemTemplate>
>
> Code behind:
>
> Protected Sub ModalOkButton_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles ModalOkButton.Click
> Try
>
> With Me.FormView1
> .ChangeMode(FormViewMode.Insert)
> .Visible = True
> End With
>
> With Me.TextBox1
> .Text = ""
> .Visible = False
> End With
>
> Me.SearchButton.Visible = False
> Me.lnkInsertTop.Visible = True
> Me.lnkInsertBottom.Visible = True
> Me.lnkEditTop.Visible = False
> Me.lnkEditBottom.Visible = False
> Me.lnkUpdateTop.Visible = False
> Me.lnkUpdateBottom.Visible = False
> Me.lnkCancelTop.Visible = True
> Me.lnkCancelBottom.Visible = True
>
> Dim TMDropDown As DropDownList
>
> TMDropDown =
> Me.FormView1.FindControl("TerritoryMgrDropDown")
>
> If UserInfo.IsInRole("TM") Then
> TMDropDown.SelectedValue =
> UserInfo.Profile.GetPropertyValue("SalesmanID")
>
> Else
> TMDropDown.Visible = True
> End If
> Trace.Write(TMDropDown.Visible.ToString)
> Trace.Write(TMDropDown.SelectedValue.ToString)
>
> Catch ex As Exception
> Throw ex
> End Try
> End Sub
>
> Thanks,
> Hollywood


Sorry gang - I was testing if the .visible was the issue or not.
Based on the trace, .visible does get set to False but when the
control renders, it is visible. It's in the InsertItem template. The
code behind looks like this:

Protected Sub ModalOkButton_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ModalOkButton.Click
Try


With Me.FormView1
.ChangeMode(FormViewMode.Insert)
.Visible = True
End With

With Me.TextBox1
.Text = ""
.Visible = False
End With

Me.SearchButton.Visible = False
Me.lnkInsertTop.Visible = True
Me.lnkInsertBottom.Visible = True
Me.lnkEditTop.Visible = False
Me.lnkEditBottom.Visible = False
Me.lnkUpdateTop.Visible = False
Me.lnkUpdateBottom.Visible = False
Me.lnkCancelTop.Visible = True
Me.lnkCancelBottom.Visible = True


Dim TMDropDown As DropDownList

TMDropDown =
Me.FormView1.FindControl("TerritoryMgrDropDown")

If UserInfo.IsInRole("TM") Then
TMDropDown.Visible = False


Else
TMDropDown.Visible = True
End If
Trace.Write(TMDropDown.Visible.ToString)
Trace.Write(TMDropDown.SelectedValue.ToString)


Catch ex As Exception
Throw ex
End Try
End Sub
 
Reply With Quote
 
 
 
 
Hollywood
Guest
Posts: n/a
 
      02-07-2008
I figured out how to make this work. I tried using FormView's
ItemCreated event before but forgot to check to see if CurrentMode =
Insert. Once I did that, it found the control and I could set its
properties.

New code:

Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal
e As System.EventArgs) Handles FormView1.ItemCreated
Try
If Me.FormView1.CurrentMode = FormViewMode.Insert Then
Dim TMDropDown As DropDownList
TMDropDown =
Me.FormView1.FindControl("TerritoryMgrDropDown")

If UserInfo.IsInRole("TM") Then
TMDropDown.Enabled = False
TMDropDown.SelectedValue =
UserInfo.Profile.GetPropertyValue("SalesmanID")

Else
TMDropDown.Visible = True
End If
End If

Catch ex As Exception
Throw ex
End Try

End Sub


Hope this helps sombody else!

HW
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
embeding databound DropDownList in FormView spoils DropDownList ev Lagrange ASP .Net Web Controls 1 01-17-2009 08:31 AM
Hide textbox / Make textbox not visible (NOT USING visible property) Jurjen de Groot ASP .Net Web Controls 0 05-19-2008 09:50 AM
button visible/not visible tshad ASP .Net 6 10-28-2004 10:02 PM
Panel.Visible = True also make child controls visible. spamfurnace ASP .Net 1 05-24-2004 03:07 AM
User control not visible when setting .Visible = true; Andrea Williams ASP .Net Web Controls 4 01-28-2004 10:22 PM



Advertisments