Telerik Rad Button Dyanamically check - vb.net

Have been unable to dynamically check a Telerik Rad Button control from the code behind in vb.net code. I have used things like chk_TypeEmployee.Checked = True with no result.
<telerik:RadButton ID="chk_TypeEmployee" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Text="Employee"></telerik:RadButton>
<telerik:RadButton ID="chk_TypeAgency" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Text="Agency"></telerik:RadButton>

You need to use ToggleStates:
<telerik:RadButton ID="chk_Type" runat="server" ToggleType="Radio" ButtonType="StandardButton" GroupName="StandardButton" Checked="true">
<ToggleStates>
<telerik:RadButtonToggleState Value="Employee" Text="Employee" PrimaryIconCssClass="rbToggleRadioChecked" />
<telerik:RadButtonToggleState Value="Agency" Text="Agency" PrimaryIconCssClass="rbToggleRadio" />
</ToggleStates>
</telerik:RadButton>
To set dynamicaly the button to "Agency" state, assuming it is the second ToggleState for the button:
chk_Type.ToggleStates[0].Selected = false;
chk_Type.ToggleStates[1].Selected = true;
Could be rewritten cleaner this way:
string DBValue = "Agency";
foreach (RadButtonToggleState state in chk_Type.ToggleStates)
{
state.Selected = state.Value.Equals(DBValue);
}
And to retrieve the selected value, use the chk_Type.SelectedToggleState.Value.
Note: The RadButton's property Checked must be set to true. And at least 1 of your toggle states should be Selected, else the first toggle state would be selected by default. In order to use more than 2 toggle states, please read about ToggleType="Custom".
Read more about Telerik's Toggle Buttons.

Related

v-date-picker does not close on tab out

I'm fairly new to vuetify and vue in general. The problem I'm facing is that when I click on a datepicker, the calendar pops up and when I tab out, the cursor moves to the next input field but the calendar does not close.
I want it to close automatically on tab out.
I tried setting close-on-content-click="true" instead of false but to no avail. I'm not sure what else to try.
Here is a codepen I found vuetify documentation that has similar implementation and behavior as my application. codepen
Thank you for any inputs.
add this #keydown.tab='menu1 = false' in v-text-field
close-on-content-click is for mouse clicks and does not apply to keyboard actions. You need to explicitly toggle the v-menu model when the input loses focus.
To close the menu when whenever the input field loses focus I would attach the toggle to the blur event. You can do this by replacing the #blur listener to a method, in which you will set the menu model to false.
<v-text-field
v-model="dateFormatted"
label="Date"
hint="MM/DD/YYYY format"
persistent-hint
prepend-icon="mdi-calendar"
v-bind="attrs"
#blur="updateDate"
v-on="on"
/>
updateDate(event) {
// This is the same value as dateFormatted,
// you don't need to say this.dateFormatted like in your codepen.
const value = event.target.value;
this.date = this.parseDate(value);
this.menu1 = false;
}
"Destructuring" is JS good practice instead of randomly named variables or verbosity so I would write the first line as:
const { value } = event.target;
If you were passing additional variables into updateDate method you would need to write it as updateDate($event, variable) but if not, $event as first parameter is a given.

Accessing RadListBox Items in Code-Behind

I have the following RadListBox:
<telerik:RadListBox ID="AttachmentsRadListBox" CheckBoxes ="true" runat="server" />
It is located in a RadWindow, therefore I am populating it through the following code which is only called when RadWidnow becomes visible:
AttachmentsRadListBox.DataSource = AttachDT
AttachmentsRadListBox.DataTextField = "DocumentPath"
AttachmentsRadListBox.DataValueField = "DocumentID"
AttachmentsRadListBox.DataBind()
For Each item As RadListBoxItem In AttachmentsRadListBox.Items
item.Checked = True
Next
So far so good, the RadListBox is populated and all the items are checked.
Now, there is a Save button on the RadWindow when pressed before closing the window I am trying to read the checked items in the AttachmentsRadListBox (Since the user might have changed the status of the checked items). But every effort on reading the items has failed, for example on the Save button click I have the following:
Dim test As Integer = AttachmentsRadListBox.Items.Count // THIS IS ZERO
For Each item As RadListBoxItem In AttachmentsRadListBox.Items // THERE ARE NO ITEMS
If Not item.Checked Then
Dim DocumentIDToDelete As Integer = item.Value
End If
Next
Why is that the last piece of code does not behave as I hope? The AttachmentsRadListBox is not being bounded again through the postback. The only time that it is bounded is when the RadWindow appears. Then the Save button on the RadWindow obviously creates a postback but I don't understand why AttachmentsRadListBox contains no item at that point.
Since you create the AttachmentsRadListBox dynamically, do you recreate it on subsequent postbacks? It is, in the end, a server control, so you need to make sure it is recreated, because otherwise ASP will destroy it upon a subsequent postback.
To see how you can access controls in the ContentTemplate of a RadWindow you can also examine this article: http://www.telerik.com/help/aspnet-ajax/window-controls-container.html.

Slow style binding in my windows store app

I have some buttons in my xaml which I want to bind the style dynamically based on some value. This all works great, but for maybe a second or two the buttons are not styled properly as my app is still loading. My application will load, but I have a list view that is waiting to receive some data from a web service. It seems as though the buttons won't be bound until the list view is bound.
Is there a way to set a "default" style on my buttons but still have my buttons bind at runtime without having to set all the properties for each button? Or why are my buttons taking so long to bind? Can I prioritize them?
Here is my button...
<Button x:Name="ButtonAll" Click="ButtonAll_Click" Style="{Binding State,Converter={StaticResource ButtonStateConverter},ConverterParameter=All}" Margin="0,0,50,0">All</Button>
Here is my converter code...
SampleState state = (SampleState)value;
SampleState param = new SampleState() { Code = (string)parameter, Name = (string) parameter };
if (state == param)
return App.Current.Resources["TextPrimaryButtonStyle"];
else
return App.Current.Resources["TextSecondaryButtonStyle"];

Flex 3: Hiding elements created by repeater

I have a repeater that creates a custom component named "Block." I need to make it so that when the user clicks a button, all of the blocks created by the repeater have their visible field set to false (and then true when the button is clicked again).
Here's some of the code I have right now:
<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
<components:block height="24"
width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"
oneDay="{oneDay}"
/>
</mx:Repeater>
Here's the button the user will click to show/hide the blocks:
<mx:Button id="showHideButton" label="Show Project" x="{addBlock.x + addBlock.width + 2}" click="showProjectSwitch();" />
Here's the function showProjectSwitch():
public function showProjectSwitch():void {
if (showHideButton.label == "Hide Project")
{
showHideButton.label = "Show Project";
indPositions.visible = false;
thisProject.height = 65;
}
else
{
showHideButton.label = "Hide Project";
indPositions.visible = true;
thisProject.height = projectHeight ;
}
}
I tried setting projectRP.visible="true/false", but it didn't work :(
I also tried wrapping a canvas around the repeater, but when I did that... the repeater only ran once despite the fact I have the startingIndex="0" and the count="16". I then removed the canvas tags and the repeater ran the correct number of times.
Anybody able to help me out?
The easiest way to achieve what you want is just to use databinding, same as you did for the "oneDay" value.
<mx:Repeater id="indPositions" dataProvider="{projectPositions}" startingIndex="0">
<components:block height="24"
width="100%" id="thisBlock" visible="true" horizontalScrollPolicy="off"
oneDay="{oneDay}"
visible="{showBlocks}"
/>
</mx:Repeater>
<mx:Boolean id="showBlocks" />
[Edit for additional clarity]
To change the visibility of the blocks, you need to set the value of showBlocks, like so:
showBlocks = true;
or
showBlocks = false;
Here's how i solved it... since the variable name of "thisBlock" is declared every time a block is made, all that information gets stored in an array. After learning this, i was able to create a for each loop in a function that was called when the show/hide button was pressed... the for each loop goes something like this:
for (var I:int = 0; i < dataprovidername.length; i++)
thisBlock[i].visible = true/flase;
Hope that can help somebody else out in the future.

FindControl in DataList Edit Mode

As a new .net/C# web begginner, I always get tripped up when I try to use FindControl. Blam -flat on my face. Here is my current FindControl problem:
I have an .aspx page and Form, then ajax updatePanel, inside it there is my DataList (DataList1) that has an EditItemTemplate: that has the following:
<EditItemTemplate>
<asp:Label ID="thumbnailUploadLabel" runat="server" text="Upload a new thumbnail image:"/><br />
<asp:FileUpload ID="thumbnailImageUpload" runat="server" />
<asp:Button ID="thunbnailImageUploadButton" runat="server" Text="Upload Now" OnClick="thumbnailUpload"/><br />
</EditItemTemplate>
In my C# code behind I have the OnClick code for the fileUpload object:
protected void thumbnailUpload(object s, EventArgs e)
{
if (thumbnailImageUpload.HasFile)
{
//get name of the file & upload
string imageName = thumbnailImageUpload.FileName;
thumbnailImageUpload.SaveAs(MapPath("../../images/merch_sm/" + imageName));
//let'em know that it worked (or didn't)
thumbnailUploadLabel.Text = "Image " + imageName + "has been uploaded.";
}
else
{
thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
}
So of course I'm getting "Object reference not set to an instance of an object" for the FileUpload and the Label.
What is the correct syntax to find these controls, before dealing with them in the OnClick event?
The only way Ive used FindControl is something like:
label thumbnailUploadLabel = DataList1.FindControl("thumbnailUploadLabel") as Label;
But of course this is throwing the "Object reference not set to an instance of an object" error. Any help is very much appreciated.
(I've also seen the 'recursive' code out there that is supposed to make using FindControl easier. Ha! I'm so green at C# that I don't even know how to incorporate those into my project.)
Thanks to all for taking a look at this.
I know this is a hell lot late but i was looking for questions to answer....you must have figured it by now but still
if you add these lines in your code
protected void thumbnailUpload(object sender, EventArgs e)
{
FileUpload thumbnailImageUpload =(FileUpload)DataList1.Items[DataList1.EditItemIndex].FindControl("thumbnailImageUpload");
Label thumbnailUploadLabel = (Label)DataList1.Items[DataList1.EditItemIndex].FindControl("thumbnailUploadLabel");
if (thumbnailImageUpload.HasFile)
{
//Your code here
}
else
{
thumbnailUploadLabel.Text = "Please choose a thumbnail image to upload.";
}
}
this will find the appropriate control for the row you are editing...
also keep your Datalist out of the UPdate Panel beacuse Update Panels are not compatible with FileUpload. if you do the code will run but it will always show thumbnailImageUpload.HasFile as False.