I have a combo box in a Form View and onchange i want to access a javascript function just as i'd normally do any drop down list. However, it doesn't seem to be even getting to the function
function Showused()
{
alert('eric');
}
<telerik:RadComboBox ID="RadComboBoxProvided" onchange="javascript: Showused();" runat="server" Width="50px" >
<Items>
<telerik:RadComboBoxItem runat="server" Text="Yes" Value="Y" />
<telerik:RadComboBoxItem runat="server" Text="No" Selected="true" Value="N" />
</Items>
</telerik:RadComboBox>
Simple javascript call. Any idea why this doesn't work?
The client-side event names are different for Telerik controls. The RadComboBox event for selected index changed (assuming you're using a recent version of the controls) is OnClientSelectedIndexChanged
You may want to consult the client-side programming guide for RadComboBox, or the list of client-side events.
Here's a sample for use with your example:
Javascript:
function SelectedIndexChanged(sender, eventArgs) {
var item = eventArgs.get_item();
alert("You selected " + item.get_text());
}
Markup:
<telerik:RadComboBox ID="RadComboBoxProvided" OnClientSelectedIndexChanged="SelectedIndexChanged" runat="server" Width="50px" >
<Items>
<telerik:RadComboBoxItem runat="server" Text="Yes" Value="Y" />
<telerik:RadComboBoxItem runat="server" Text="No" Selected="true" Value="N" />
</Items>
</telerik:RadComboBox>
is not a combo box, it is a custom tag, that will convert itself to an HTML combo box, to be sure what is happening there, run your server and go to that page, and then right click on the page in your browser and look at the HTML source, and finally try to locate that combo box and see how it is really rendered.
Related
First Issue,I have two controls (a radcombox and a Treelist controls) on my page. On radcombobox's SelectedIndexChanged I am populating data from database.Now I want to fire NeedDatasource event on SelectedIndexChanged. How could I do that ?
Second issue,
As I am facing some issues with needdatasource, I have manually binded using databind method of radtreelist.After binding it shows only parent nodes at first.
After clicking on PageSize combo of RadTreelist, it loads with respective child nodes.Why is this happening here ?
<telerik:RadComboBox runat="server" ID="rcb_testtype" AutoPostBack="True" OnSelectedIndexChanged="rcb_testtype_OnSelectedIndexChanged">
<Items>
<telerik:RadComboBoxItem runat="server" Text="Select a Test Type" Value="-1" />
<telerik:RadComboBoxItem runat="server" Text="Practise Test" Value="pt" />
<telerik:RadComboBoxItem runat="server" Text="Normal Test" Value="nt" />
</Items>
</telerik:RadComboBox>
<telerik:RadTreeList ID="rtl_specific_topic" runat="server"
ParentDataKeyNames="parent_topicid" DataKeyNames="topicid" AllowPaging="true" RenderMode="Classic" Skin="WebBlue"
AutoGenerateColumns="false" AllowSorting="true" ExpandCollapseMode="Client" AllowRecursiveSelection="False" OnItemDataBound="rtl_specific_topic_OnItemDataBound"
AllowMultiItemSelection="true" OnItemCommand="RadTreeList1_ItemCommand" OnPageSizeChanged="RadTreeList1_PageSizeChanged" OnPageIndexChanged="RadTreeList1_PageIndexChanged">
<Columns>
<telerik:TreeListSelectColumn HeaderStyle-Width="38px">
</telerik:TreeListSelectColumn>
<telerik:TreeListBoundColumn DataField="parent_topicid" UniqueName="parent_topicid" HeaderText="Parent Topic Id" Visible="False">
</telerik:TreeListBoundColumn>
<telerik:TreeListBoundColumn DataField="topicid" UniqueName="topicid" HeaderText="Topic ID" Visible="False">
ion" UniqueName="description" HeaderText="Topic Name">
</telerik:TreeListBoundColumn>
<telerik:TreeListTemplateColumn HeaderText="Weightage" UniqueName="syllabus_weightage" HeaderStyle-Width="95px" ItemStyle-Width="95px">
<ItemTemplate>
<telerik:RadNumericTextBox runat="server" ID="rntb_weightage" MinValue="0" Width="80px" MaxValue="100" EmptyMessage="weightage(%)" AllowRounding="true"></telerik:RadNumericTextBox>
</ItemTemplate>
</telerik:TreeListTemplateColumn>
<telerik:TreeListTemplateColumn HeaderText="Weightage" UniqueName="quest_category">
<ItemTemplate>
<asp:DropDownList ID="ddl_quest_category" runat="server" Width="100px" style="right: 1px;">
<asp:ListItem Text="select a question type" Value="-1"></asp:ListItem>
<asp:ListItem Text="Multiple Choice" Value="1"></asp:ListItem>
<asp:ListItem Text="True/False" Value="2"></asp:ListItem>
<asp:ListItem Text="Essay Writing" Value="3"></asp:ListItem>
<asp:ListItem Text="Pictorial" Value="4"></asp:ListItem>
<asp:ListItem Text="Short Question" Value="5"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle Width="90px"></HeaderStyle>
</telerik:TreeListTemplateColumn>
<telerik:TreeListTemplateColumn HeaderText="Set Level" UniqueName="level">
<ItemTemplate>
<telerik:RadSlider runat="server" ID="rs_level" Skin="Web20" Width="490px" AutoPostBack="True"
Height="70px" CssClass="dragRangeSlider" EnableServerSideRendering="true" IsSelectionRangeEnabled="true" OnValueChanged="rs_level_OnValueChanged"
EnableDragRange="true"
ItemType="Item">
<Items>
<telerik:RadSliderItem Text="L1" Value="1" runat="server"></telerik:RadSliderItem>
<telerik:RadSliderItem Text="L2" Value="2" runat="server"></telerik:RadSliderItem>
</Items>
</telerik:RadSlider>
</ItemTemplate>
<HeaderStyle Width="490px"></HeaderStyle>
<ItemStyle Width="490px"></ItemStyle>
</telerik:TreeListTemplateColumn>
</Columns>
</telerik:RadTreeList>
OnSelectedIndexChanged bind radtreelist
in Code behind
protected void rcb_testtype_OnSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
rcb_syllabus_name.Visible = rcb_testtype.SelectedValue != "pt";
rtl_specific_topic.DataSource = FetchTopicDetailsForSyllabus();
rtl_specific_topic.DataBind();
}
private DataTable FetchTopicDetailsForSyllabus()
{
DataTable dtTopocsForTest = null;
if (rcb_testtype.SelectedValue == "nt" && rcb_syllabus_name.SelectedValue != "")
{
obj_BEL_LMS.Flag = "normaltest";
obj_BEL_LMS.Syllabusid = Convert.ToInt32(rcb_syllabus_name.SelectedValue);
dtTopocsForTest = obj_BL_LMS.FetchSyllabusDetails(obj_BEL_LMS);
}
else if (rcb_testtype.SelectedValue == "pt")
{
obj_BEL_LMS.iFlag = 2;
obj_BEL_LMS.iBranchId = Convert.ToInt32(Session["branchid"]);
dtTopocsForTest = obj_BL_LMS.FetchTopicDetailsDb(obj_BEL_LMS);
}
return dtTopocsForTest;
}
After binding it shows only parent data.
From the Telerik documentation:
This event fires in the following cases:
Right after OnLoad, Telerik RadTreeList checks the viewstate for stored TreeList-related information. If such information is missing (when the page loads for the first time), the NeedDataSource event is fired. This also means that if the EnableViewState property of the control has been set to false, the treelist will bind each time the page loads (not only the first time)
After expand/collapse
When paging event occurs
When other operations requiring Rebind occurs
The advantages of using this event are that the developer does not need to write any code handling the logic about when and how the data-binding should be processed. It is still the developer's responsibility to construct properly a data source object and assign it to the RadTreeList's DataSource property.
In the code of the NeedDataSource handler you should prepare the data source (list of objects) for Telerik RadTreeList and assign it to the grid's DataSource property. Also you should set the DataKeyNames and ParentDataKeyNames propertied for the TreeList control.
Note: You should never call the DataBind() method from inside the NeedDataSource handler or mix simple data-binding mode with advanced data-binding
I suggest you edit your post and include your code.
This combo box is in an asp.net page and the intention is to bind it to a nvarchar(50).
The user select one of the values and then update the DB.
<telerik:RadComboBox ID="RadComboBox1" runat="server" SelectedValue='<%# Bind("inBudgetTT") %>'>
<Items>
<telerik:RadComboBoxItem Text="In Budget" />
<telerik:RadComboBoxItem Text="Not In Budget" />
</Items>
</telerik:RadComboBox>
The problem: doesn't matter what I select, it is never written in the DB. Any hint on how to solve the problem?
Use the SelectedIndexChanged event to update your database: http://www.telerik.com/help/aspnet-ajax/combobox-server-side-selectedindexchanged.html. The SelectedValue property only indicates what the control should show as a selected item.
I have two questions that are in the form of radio button lists in C# web application. These questions have required field validators associated to them and I also have a ValidationSummary at the end of my web control. When I click on my "Submit" button, the two required field validations appear for each of the questions right next to it and the validationsummary works correctly by stating "Answer the following questions:" and then listing each of the questions that were not selected. The problem I'm having is when I select one of the two questions, the "Required Field" message disappears next to the question, but not in the ValidationSummary. How can I get the ValidationSummary to update or refresh when one of the questions in the error messages are selected? Please let me know if I need to be more specific. Thanks for your help!
<asp:RadioButtonList ID="Question1" RepeatLayout="Flow" runat="server">
<asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
<asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
Text="Required" ErrorMessage="Question 1"
Display="Dynamic" ControlToValidate="Question1"
EnableClientScript="true">
</asp:RequiredFieldValidator>
<asp:RadioButtonList ID="Question2" RepeatLayout="Flow" runat="server">
<asp:ListItem Text="Yes" Value="Yes"></asp:ListItem>
<asp:ListItem Text="No" Value="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
Text="Required" ErrorMessage="Question 2"
Display="Dynamic" ControlToValidate="Question2"
EnableClientScript="true">
</asp:RequiredFieldValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Answer the following questions:"
DisplayMode="BulletList"
EnableClientScript="true"/>
<asp:Button ID="buttonSubmit" runat="server" Text="Submit"
OnClick="btnSubmit_OnClick"/>
//Code behind for button
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
Response.BufferOutput = true;
Response.Redirect("~/Page.aspx");
}
I'm pretty sure the summary doesn't dynamically update by default, but rather only on form submit.
Ordinarily, you could get around this by hooking the client-side onblur event and calling ValidationSummaryOnSubmit(), but it looks like the RadioButtonList doesn't trigger this event when the selected radio button changes.
The next candidate would be the client-side onClick event, but the RadioButtonList control doesn't have an OnClientClick event.
So, the solution which worked for me when I tested it was to hook the client-side onClick event for each ListItem in the RadioButtonList. Like this:
<asp:RadioButtonList ID="Question1" RepeatLayout="Flow" runat="server">
<asp:ListItem Text="Yes" Value="Yes" onClick="ValidationSummaryOnSubmit()"></asp:ListItem>
<asp:ListItem Text="No" Value="No" onClick="ValidationSummaryOnSubmit()"></asp:ListItem>
</asp:RadioButtonList>
However, this will get rapidly ugly if you've got a bunch of these that you're going to want to do. Might consider subclassing RadioButtonList and adding a server-side addition of the ListItem onclick hook to each of the child listitems before sending it to the client, and then using your custom version of RadioButtonList instead of the stock version.
I have two radio buttons for metric and US measurements. I load the page so the metric radio button is clicked. How do I set the two buttons so when US is clicked metric unclicks and vise versa?
In order to make it work, you have to set property GroupName of both radio buttons to the same value:
<asp:RadioButton id="rbMetric" runat="server" GroupName="measurementSystem"></asp:RadioButton>
<asp:RadioButton id="rbUS" runat="server" GroupName="measurementSystem"></asp:RadioButton>
Personally, I prefer to use a RadioButtonList:
<asp:RadioButtonList ID="rblMeasurementSystem" runat="server">
<asp:ListItem Text="Metric" Value="metric" />
<asp:ListItem Text="US" Value="us" />
</asp:RadioButtonList>
Make sure their GroupName properties are set to the same name:
<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="US" />
<asp:RadioButton GroupName="MeasurementSystem" runat="server" Text="Metric" />
I can see it's an old question, if you want to put other HTML inside could use the radiobutton with GroupName propery same in all radiobuttons and in the Text property set something like an image or the html you need.
<asp:RadioButton GroupName="group1" runat="server" ID="paypalrb" Text="<img src='https://www.paypalobjects.com/webstatic/mktg/logo/bdg_secured_by_pp_2line.png' border='0' alt='Secured by PayPal' style='width: 103px; height: 61px; padding:10px;'>" />
<asp:RadioButtonList id="RadioButtonList1" runat="server">
<asp:ListItem Selected="True">Metric</asp:ListItem>
<asp:ListItem>US</asp:ListItem>
</asp:RadioButtonList>
Set the GroupName property of both radio buttons to the same value. You could also try using a RadioButtonGroup, which does this for you automatically.
I want to show a modal popup when a user click on an asp button. The user must select an option of a panel. The value of the option selected must be saved to an input hidden and then the asp.net button must do a PostBack.
Can I do that?
Thank you!
It is possible for a ModalPopupExtender to be displayed using a postback. You'll need an invisible target control. The extender is attached to this hidden control.
<asp:Button runat="server" ID="btnShowModal" Text="Show"
OnClick="btnShowModal_Click" />
<asp:Button runat="server" ID="HiddenForModal" style="display: none" />
<ajaxToolKit:ModalPopupExtender ID="Modal1" runat="server"
TargetControlID="HiddenForModal" PopupControlID="PopupPanel" />
In your message handler in code-behind, you'll show the ModalPopupExtender:
Modal1.Show();
And in the code you're using to dismiss the Modal, call the ModalPopupExtender's Hide function:
Modal1.Hide();
I use this method for showing a modal that displays detailed data that I retrieve from a database based on what's selected in a GridView.
Add your Button or LinkButton
<asp:Button ID="MyButton" Text="Click Here" runat="server" />
Add a Panel to hold your options with a DropDownList
<asp:Panel ID="MyPanel" runat="server">
<asp:DropDownList ID="MyDropDown" runat="server">
<asp:ListItem Value="1" Text="Option 1" />
</asp:DropDownList>
<asp:Button ID="SaveBtn" Text="Save" OnClick="Save_Click" runat="server" />
<asp:Button ID="CancelBtn" Text="Cancel" runat="server" />
</asp:Panel>
Add your ModelPopupExtender
<act:ModalPopupExtender ID="Mpe1" TargetControlID="MyButton"
CancelControlID="CancelBtn" PopupControlID="MyPanel" runat="server" />
Then add your code behind to the SaveBtn Button
public void SaveBtn_Click(object sender, EventArgs e) {
string selectedOption = MyDropDown.SelectedValue;
}
Finally, I've decided to use jQuery to show a ModalPopUp. The following question has the answer to this question:
jQuery UI's Dialog doesn't work on ASP.NET
If you are not agree, tell me.