Reputation: 395
I have a page that's used by two different users. If the logged in user is 'user1' i display all 8 fields and if its 'user2' i display 7 out of the 8 fields. This is the html code i use to hide the one field from user2.
<%If User1 Then%>
<tr>
<td>
<cc1:Label ID="lblTextBox1" runat="server" />
<cc1:TextBoxId ID="txtTextBox1" runat="server" LabelId="lblTextBox1" Columns="20" />
</td>
</tr>
<%End If%>
Now, when the aspx.vb page loads, it populates all these controls together, but this one field remain hidden because of the above html code. When the save button on the page is clicked, the save method dioes not try to distinguish between user1 and user2, but extract values from all the controls and saves.
My problem is when user2 'saves', the values of the 'hidden' textbox isbecoming null, though at the time the other controls were populated, this field also waspopulated. Somehow the values became '' at the point am saving it
Why is this happening like this? What is the best solution/work-around to this?
Upvotes: 0
Views: 1005
Reputation: 1118
A quick and dirty workaround would be to explicitly save the value of that control into ViewState or a Session and manually repopulate it. The issue probably stems from all the classic ASP style code blocks on the page.
Upvotes: 0
Reputation: 6047
<asp:Panel id="pnlForUser2" runat="server">
<tr>
<td>
<cc1:Label ID="lblTextBox1" runat="server" />
<cc1:TextBoxId ID="txtTextBox1" runat="server" LabelId="lblTextBox1" Columns="20" />
</td>
</tr>
</asp:Panel>
and in the code behind:
if(Page.User.Identity.Name.Equals("user2"))
pnlForUser2.Visible = true;
or use shorthand operators ??
Upvotes: 0
Reputation: 4101
Rather than using render blocks, have you thought about setting the visibility in the code?
Upvotes: 1