update rad ajax manager from codebehind - vb.net

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>

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>

OnUploadedComplete function of AsyncFileUpload is never hit in detailsview

I have an AsyncFileUpload control in a detailsview. I can browse to select a file to upload. When I start the upload the OnClientUploadComplete function uploadRoomThumbComplete method is executed, but the function in OnUploadedComplete is never hit.
Why?
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DetailsView AutoGenerateRows="False" DefaultMode="Edit" Width="100%" DataKeyNames="id" DataSourceID="odsDetails" ID="dvOfferDetails" runat="server">
<Fields>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Bottom" HeaderText="<%$Resources:Glossary,image%>">
<EditItemTemplate>
<asp:literal ID="ltImage" runat="server" />
<p id="RoomContainer">
</p>
<asp:literal ID="ltDeleteRoomThumb" runat="server" />
<cc1:AsyncFileUpload CssClass="imageUploaderField" ID="afuRoomThumb" Width="150" runat="server" ClientIDMode="AutoID" OnUploadedComplete="afuRoomThumb_UploadedComplete" OnClientUploadComplete="uploadRoomThumbComplete" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub afuRoomThumb_UploadedComplete(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs)
'---> this codeblock is NEVER hit....why?
End Sub
Ok, I found the answer here: http://forums.asp.net/t/1477331.aspx?AsyncFileUpload+inside+a+GridView+inside+an+UpdatePanel
In short: place another AsyncFileUpload control on the page and set the style's display:none.
It seems that the AsyncFileUpload is designed to be used only once on a page, and when you put it on your master page, any afu inside an updatepanel will work.

Run asp.net required field validation only if at least one of the fields in the group is completed

I have a form on an asp.net (VB) page which has 2 sections.
All of section 1 is always required, but section 2 is optional. However, if section 2 is started, then all fields are required.
I'm stuck as to the logic I need to create this validation.
Here's my code:
<form runat="server">
<div>
<asp:TextBox runat="server" ID="field1a" Text="Name" />
<asp:TextBox runat="server" ID="field1b" Text="City" />
<asp:RequiredFieldValidator runat="server" ID="field1aVal" Text="Name Required" ControlToValidate="field1a" InitialValue="Name" />
<asp:RequiredFieldValidator runat="server" ID="field1bVal" Text="City Required" ControlToValidate="field1b" InitialValue="City" />
</div>
<div>
<asp:TextBox runat="server" ID="field2a" Text="Name" />
<asp:TextBox runat="server" ID="field2b" Text="City" />
<asp:RequiredFieldValidator runat="server" ID="field2aVal" Text="Name Required" ControlToValidate="field2a" InitialValue="Name" />
<asp:RequiredFieldValidator runat="server" ID="field2bVal" Text="City Required" ControlToValidate="field2b" InitialValue="City" />
</div>
<asp:button runat="server" ID="btnSubmit" Text="Submit" OnClick="submitForm" />
</form>
Id say use required fields on section 1, but for section two use a custom validator. Something like this.
<asp:CustomValidator ID="CustomValidator2" runat="server"
Display="Dynamic" EnableClientScript="False"
ErrorMessage="You must select one checkbox or click all offices. " OnServerValidate="OfficeVaildator">
</asp:CustomValidator>
Then in code behind do your logic
Something like this
Sub OfficeVaildator(ByVal source As Object, ByVal args As ServerValidateEventArgs)
If OfficeCheckBoxs.Checked Then
args.IsValid = True
Else
args.IsValid = False
End If
End Sub
Obviously that is really simple. You would want to check if the user altered section 2 in anyway, and if he did make him complete all fields to return your server validation arguments true. If he didnt alter section 2 or give it any data right a method that checks that and set your validation to true to allow him to proceed.

Make UserControl Visible after Logging In

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).

Sending email to all the email adresses in gridview which are checked

I have a grid view control in my application.
Please see the below code.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CPUserID" DataSourceID="GetSelectDelegatesDataSource">
<Columns>
<asp:BoundField HeaderStyle-CssClass="gridview_header" HeaderStyle-ForeColor="White" Visible="false" DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress">
<HeaderStyle CssClass="gridview_header" ForeColor="White"></HeaderStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<input id="masterCheck" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkSelect" />
</ItemTemplate>
<HeaderStyle CssClass="gridview_header" ForeColor="White"></HeaderStyle>
</asp:TemplateField>
</Columns>
</asp:GridView>
And I have a image button
<asp:ImageButton ID="ibtnSendInvites" Visible="false" runat="server" ImageUrl="~/images1/send_button.png" />
If you see above code you can find that there is check box functionality in my gridview. I have email address boundfield in my gridview. I want to send an email to the email addresses which are been checked in gridview.
Please provide the vb.net code for the same
Very quickly thrown together, you can get the jist.. I didn't test it or anything.
Dim emailList As New List(Of String)
For Each curRow As GridViewRow In GridView1.Rows
Dim chkSelect As CheckBox = CType(curRow.Cells(1).FindControl("chkSelect"), CheckBox)
If chkSelect.Checked Then
emailList.Add(curRow.Cells(0).Text)
End If
Next
' you now have a generic list of email addresses..
System.Web.Mail provide the functionality to send mail from .Net framework. Download the sample project Send Mail- codeproject and see how this is implemented.
Check this link on BulkEditGridView. It's just like a GridView, but you can edit (or perform actions on) multiple rows of a gridview with one click. I use it and love it.