Make UserControl Visible after Logging In - vb.net

I have a popup login usercontrol in a masterpage, once logged in I want another usercontrol on a content page to appear automatically, currently it only appears if I manually refresh the page. How can this be accomplished. Thanks.
MasterPage - > login usercontrol
View.aspx - > bookmark usercontrol (should appear after logging in)
login usercontrol in Master Page
<asp:UpdatePanel ID="login" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlLogin" runat="server">
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password </asp:TextBox>
<asp:Button ID="btbookmark" runat="server" Text="Login" OnClick="btbookmark_Click"/>
</asp:Panel>
<asp:Panel ID="pnlData" runat="server">Placeholder for bookmark data. Bookmark data goes here.
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Bookmark usercontrol on View.aspx
<asp:TextBox ID="txtbookmark" runat="server"></asp:TextBox><br />
<asp:Button ID="btmark" runat="server" />
After logging in how can the Bookmark usercontrol on View.aspx appear. Do I need to use an updatepanel?

You could either register it and set the Visible property to false in the code behind, until the user has logged in, and then you set the property to true. You will need to add code to prevent a lot of processing if the user session object doesn't exist.
aspx:
<%# Register TagPrefix="control" TagName="UserBookmarks" Src="~UserBookmarks.ascx" %>
<control:UserBookMarks ID="UserBookmarksCtrl" runat="server" Visible="false" />
code behind:
// If user logged in
UserBookmarksCtrl.Visible = True
Or, you can dynamically create the control, and add it to your page once a user has logged in (i.e. something like Session["user"] has been set).

Related

I want my Checkboxlist to be automatically filled on page loading

I have created a hobbies checkboxlist and want it to be automatically filled on page loading after particular user logs in. The checkboxes should be checked according to the hobbies stored in database records for a user. I have no idea how to do it.
I doing code in vb.net, here is my code for User_Form.aspx
<asp:Label ID="lblSelectHobbies" runat="server" Text="Select hobbies"></asp:Label>
<br />
<asp:CheckBox ID="chbSelectAllHobbies" runat="server" Text="Select all" OnCheckedChanged ="chbSelectAllHobbies_CheckedChanged" AutoPostBack="true"/>
<br />
<asp:CheckBoxList ID="cblHobbies" runat="server" DataSourceID="SqlDataSource_Hobby" DataTextField="Hobbies" DataValueField="Hobbies">
</asp:CheckBoxList>
</td>

.aspx page does not load after adding Validators in VB.Net

I have an aspx page with a few FormViews and an updateable GridView that I would like to add validation for. The fields that I am trying to validate are also using the CalendarExtender from the AJAX Control Toolkit by the way. I am trying to use the RequiredFieldValidator and RangeValidator for this. The problem is I don't see any errors from within VisualStudio 2015 while adding the validators. But when I run debug mode and click the button to open a FormView that contains validation I get a 500 error without any useful information to find/fix my problem.
I first tried adding both of the validators at once but after having problems, I am just trying to get the RequiredFiledValidator working. But I still need to know how to get the RangeValidator to work properly. For the RangeValidator, I want to validate a start date of no less than today and an end date that is greater than the start date. I tried using all of the examples that I found on these pages:
[1] https://www.c-sharpcorner.com/UploadFile/17e8f6/requiredfieldvalidator-control-in-Asp-Net/
[2] https://asp.net-tutorials.com/validation/required-field-validator/
[3] http://www.java2s.com/Tutorial/ASP.NET/0160__Validation/UseaspRangeValidatortocheckthevaluerangeinanasptextbox.htm
[4] http://www.informit.com/articles/article.aspx?p=101137&seqNum=5
[5] https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.rangevalidator.minimumvalue?view=netframework-4.8
[6] https://www.tutorialspoint.com/asp.net/asp.net_validators.htm
Here is an example of one of the FormViews that I am trying to validate. In the RangeValidator I just have hard coded Max and Min values but I eventually want to have the Min value to be the same value that is in the begin date text box plus day:
<asp:FormView ID="fvNotification" runat="server" Visible="False" DefaultMode="Insert" GridLines="Both" DataSourceID="SqlUserDetails">
<InsertItemTemplate>
<asp:Table ID="Table1" runat="server">
<asp:TableHeaderRow>
<asp:TableHeaderCell>Notification</asp:TableHeaderCell>
<asp:TableHeaderCell>Filter 1</asp:TableHeaderCell>
<asp:TableHeaderCell>Filter 2</asp:TableHeaderCell>
<asp:TableHeaderCell>Begin Date</asp:TableHeaderCell>
<asp:TableHeaderCell>End Date</asp:TableHeaderCell>
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell>
<asp:DropDownList ID="ddNotification" runat="server" DataSourceID="SqlNotifications" DataTextField="Name" DataValueField="Name" ></asp:DropDownList></asp:TableCell>
<asp:TableCell>
<asp:DropDownList ID="ddFilterInsrt" runat="server" DataSourceID="SqlFilters1" DataTextField="Filter" DataValueField="Filter" ></asp:DropDownList></asp:TableCell>
<asp:TableCell>
<asp:DropDownList ID="ddFilterInsrt2 runat="server" >
<asp:ListItem>*</asp:ListItem>
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TextBoxDateBgnInsrt" runat="server" autocomplete="Disabled" ></asp:TextBox>
<ajaxToolkit:CalendarExtender runat="server" BehaviorID="TextBoxDateBgnInsrt_CalendarExtender" TargetControlID="TextBoxDateBgnInsrt" ID="TextBoxDateBgnInsrt_CalendarExtender"></ajaxToolkit:CalendarExtender>
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="TextBoxDateEndInsrt" runat="server" autocomplete="Disabled" ></asp:TextBox>
<ajaxToolkit:CalendarExtender runat="server" BehaviorID="TextBoxDateEndInsrt_CalendarExtender" TargetControlID="TextBoxDateEndInsrt" ID="TextBoxDateEndInsrt_CalendarExtender"></ajaxToolkit:CalendarExtender>
<asp:RangeValidator runat="server" id="rngDate" controltovalidate="TextBoxDateEndInsrt" type="Date" MaximumValue='09/20/2011' MinimumValue="09/01/2011" errormessage="Please enter a valid date within 2006!" display="Dynamic"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" CausesValidation="True" />
<asp:Button ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" OnClick="InsertCancelButton_Click1" />
<asp:Button ID="InsertClearEndDateButton" runat="server" Text="Clear End Date" OnClick="InsertClearEndDateButton_Click"/>
</InsertItemTemplate>
</asp:FormView>
I am expecting the FormView to be visible and validate after clicking the button that make the FormView visible but instead I am getting a 500 error.

vb.net label won't show session variable

Why does this label show up in my rendered HTML??
<asp:Label ID="Label1" runat="server" Visible='<%# false %>' Text='HERE' />
I can set the visible to false in the code behind and then it will go away, but what I really want is to set visibility depending on a session variable existing, like this:
<asp:Label ID="Label2" runat="server" Visible='<%# isnothing(Session("Login_ID")) %>' Text='THERE' />
I could swear I've don't this before, but today it isn't working.
I think it's because you aren't telling the Page to bind. Other controls can be bound automatically, such as DataGrids, but you have to tell the page to do it manually.
I think I used to do it like this, somewhere where it made sense (e.g., PreRender lifecycle event):
' Me is the Page; call this from the page to bind its controls that use the <%# %> syntax
Me.DataBind()
Or, since this is relatively static, use the following in the aspx (equals sign for assignment, rather than # for binding):
<asp:Label ID="Label2" runat="server" Visible='<%= isnothing(Session("Login_ID")) %>' Text='THERE' />

update rad ajax manager from codebehind

Hi can someone help me how to call (or refresh) below control from code behind?
Currently it is working when I click my btnUpdate button. Along with I want to refresh the same usercontrol when I press another button also (ex: btnrefresh).
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnUpdate">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
<ClientEvents OnRequestStart="RequestStart" OnResponseEnd="ResponseEnd" />
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" />
<asp:Panel ID="Panel1" runat="server" Width="100%">
<uc:EmpEnrollment runat="server" ID="EmpEnrollment" />
</asp:Panel>
Just add another AjaxSetting for your btnrefresh in your AjaxSettings like below:
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="btnUpdate">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="btnrefresh">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="RadAjaxLoadingPanel1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>

Can I edit inside of a modal popup?

I have only found posts in which people using gridviews and modal popups need help with editing. However, I am not using a gridview so editing is not as simple as an edit within a gridview. The modal popup disappears when I click on the edit button. Here is what I have so far, but in the codebehind I get an error saying that my modal isn't declared.
In the image below, the little pencil image next to the close button is what I click on to edit the description. When I click on it, the modal disappears, so I cannot edit the text.
<!-- Descriptions -->
<asp:TabPanel ID="tab2" runat="server" HeaderText="Descriptions">
<HeaderTemplate>Descriptions</HeaderTemplate>
<ContentTemplate>
<ul class="info">
<asp:ListView ID="lvDescriptions" runat="server"
DataSourceID="dsAdminMarketingDescriptions" DataKeyNames="MarketingID">
<ItemTemplate>
<li class="item">
<asp:LinkButton ID="ViewDescriptionButton" runat="server"><%#
Eval("Title")%>
</asp:LinkButton>
<asp:ImageButton ID="DeleteDescriptionButton" runat="server"
Style="float:right;" AlternateText=""
ImageUrl="../../images/delete.png" CommandName="Delete"
OnClientClick="return confirm('Are you sure you want to delete this
description?')" />
<asp:Panel ID="ViewDescriptionPanel" runat="server"
CssClass="DescModalPopup">
<div class="PopupHeader">View Description -- <%#Eval("Title") %>
<asp:ImageButton ID="CancelDescriptionButton" runat="server"
ImageUrl="../../images/cancel.png" AlternateText=""
Style="float:right;"/>
<asp:ImageButton ID="EditDescriptionButton" runat="server"
ImageUrl="../../images/edit.png" AlternateText=""
Style="float:right;" CommandName="edit" AutoPostBack="false" />
</div>
<asp:Label ID="Description" runat="server" style="padding:2px;">
<%# Eval("Data")%>
</asp:Label>
</asp:Panel>
<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server"
BackgroundCssClass="modalBackground" DropShadow="false"
DynamicServicePath="" Enabled="true"
PopupControlID="ViewDescriptionPanel"
TargetControlID="ViewDescriptionButton"
CancelControlID="CancelDescriptionButton">
</asp:ModalPopupExtender>
</li>
</ItemTemplate>
Protected Sub EditDescriptionButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
ViewDescriptionModal.Show()
End Sub
UPDATE: i changed the codebehind, but I still get an error saying ViewDescriptionModal is not declared.
Protected Sub EditDescriptionButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim myControl As Control = FindControl("ViewDescriptionModal")
If (Not myControl Is Nothing) Then
ViewDescriptionModal.Show()
Else
'Control not found
End If
End Sub
UPDATE: I have created a second modal popup for edits and changed the Label to a Textbox to pull in information from the database to edit. I added a submit button, but when I click on it, I get an error saying something about it being potentially dangerous.
Does anyone have any experience with A potentially dangerous Request.Form value was detected from the client
I haven't tested this, but you may have luck if you use two modalpopupextenders, and two panels, one for viewing and one for editing.
<asp:ModalPopupExtender ID="ViewDescriptionModal" runat="server"
BackgroundCssClass="modalBackground" DropShadow="false"
DynamicServicePath="" Enabled="true"
PopupControlID="ViewDescriptionPanel"
TargetControlID="ViewDescriptionButton"
CancelControlID="CancelDescriptionButton">
</asp:ModalPopupExtender>
<asp:ModalPopupExtender ID="EditDescriptionModal" runat="server"
BackgroundCssClass="modalBackground" DropShadow="false"
DynamicServicePath="" Enabled="true"
PopupControlID="EditDescriptionPanel"
TargetControlID="EditDescriptionButton">
</asp:ModalPopupExtender>
<asp:Panel ID="ViewDescriptionPanel" runat="server" ... </asp:panel>
<asp:Panel ID="EditDescriptionPanel" runat="server" ... </asp:Panel><code>
try in your image button autopostback="false"