Im using Devexpress ASP.NET AJAX ComboBox and trying to filter the result using callback events. This is the ASP markup for the ComboBox control
<dx:ASPxComboBox runat="server"
EnableViewState="false"
Width="100%" ID="Project"
ValueField="Value" TextField="Text"
CallbackPageSize="10"
EnableCallbackMode="true"
IncrementalFilteringMode="Contains"
OnItemsRequestedByFilterCondition="Project_ItemsRequestedByFilterCondition"
OnCallback="Project_Callback"
DropDownRows="10"
TextFormatString="{0} {1}">
<Columns>
<dx:ListBoxColumn Caption="Projekt" FieldName="Value" Name="value" />
<dx:ListBoxColumn Caption="Kund" FieldName="Text" Name="text" />
</Columns>
</dx:ASPxComboBox>
And here is the code behind
protected void Project_ItemsRequestedByFilterCondition(object source, DevExpress.Web.ListEditItemsRequestedByFilterConditionEventArgs e)
{
var data = handler.GetProjectList(e.Filter);
Project.DataSource = data;
Project.DataBind();
}
protected void Project_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
{
}
Every time i try to write in the combobox the page says that the IEventCallBackHandler is not found. Please see the attached image.
I found the problem. The page is inherit our own base class that has a custom implementation of FindControl.
Related
I have an asp.net treeview which uses the OnSelectedNodeChanged event and works ok, but if you click the same node again it doesn't fire, any ideas how to get round this?
Treeview:
<asp:TreeView ID="tvSOWASP" runat="server" ImageSet="Arrows"
ShowLines="True" OnTreeNodePopulate="PopulateNode" OnSelectedNodeChanged="SelectNode">
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Expanded="True" ImageUrl="~/tree2/icons/book.gif"
SelectAction="None" Text="Schemes Of Work" Value="Schemes Of Work">
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
Code-Behind:
protected void SelectNode(Object sender, EventArgs e)
{
// Code here, ok when select any node, select same node and this code is not hit
}
Hey Please try this one.
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e){
// Do whatever you're doing
TreeView1.SelectedNode.Selected = false;
}
Hope it helps you
According to me OnSelectedNodeChanged event of any control will be the ID of that control with the event name like your control name is tvSOWASP so it's event would be tvSOWASP_SelectedNodeChanged not SelectNode so change your SelectedNodeChanged event with my code like
protected void tvSOWASP_SelectedNodeChanged(object sender, EventArgs e)
{
// Your code...
}
so remove your OnSelectedNodeChanged="SelectNode" from your code and also it's click event and try to make a new event as per i mentioned.
Hope it understand and worked for you.
It will not fire when you click the same node again because the second time the selection is not changing so the selectednodechanged event wouldn't fire.
Please refer this link
I found the deselecting the current node at the end of the SelectedNodeChanged event caused problems later on during the page cycle. When the control itself rendered it wasn't showing the selected node.
Instead I added some code to the Page_Load event to clear out the current selection.
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack) {
string eventTarget = Page.Request["__EVENTTARGET"];
if(eventTarget == TreeView1.ClientID.Replace('_', '$')) {
// The TreeView is posting back a selection change
// Clear out any existing selection so that selecting the same node
// will trigger the change event.
TreeView1.SelectedNode.Selected = false;
}
}
}
Use e.Node.Collapse(); in the treeView_TreeNodeExpanded
im new to asp.net.. please bear with me if ma question is way too trivial!!! :)
im using an accordian control within an update panel. and i also have a button to save some data frm the accordian control! - This complete is a user control which is used in another .aspx page.
now in the page_load event of the user control i initialize my database connection which works absolutely fine while loading data to the accordian.. but when i click on save, in the save button click even handler the database connection object is always null..!! (even though it is initialized in the page_load) please help..
.ascx is as here:
<asp:UpdatePanel ID="PrefPanel" runat="server" >
<ContentTemplate>
<ajaxToolkit:Accordion ID="PrefAccordion" runat="server" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent"
BackColor="#E8EAF7" Height="530px" Width="500px" AutoSize="None" RequireOpenedPane="false"
BorderStyle="Solid" BorderWidth="1" BorderColor="Black">
<Panes>
<ajaxToolkit:AccordionPane ID="ProjCategoryPaneID" runat="server">
<Header > Project Category</Header>
<Content>
<asp:Panel ID="ProjCategoryPanel" runat="server" Width="100%">
<table align="center" width="100%">
<tr></tr>
<tr>
<td align="left">
<asp:CheckBoxList RepeatDirection="Vertical" TextAlign="Left" ID="ProjCategoryItem1" runat="server" AutoPostBack="false" CausesValidation="false" />
</td>
</tr>
</table>
</asp:Panel>
</Content>
</ajaxToolkit:AccordionPane>
<asp:Button ID="btnSavePref" CssClass="buttonsmall" runat="server" Text="Save" Width="60px" OnClick="btnSavePref_Click"/>
<asp:Button ID="btnCancelPref" CssClass="buttonsmall" runat="server" Text="Cancel" Width="60px" />
</ContentTemplate>
</asp:UpdatePanel>
the code behind is as here:
public partial class UserPreferences : System.Web.UI.UserControl
{
private EAReportingDAL m_DataAccessLayer = null;
// Projects Category
Panel projectCategoryPanel;
CheckBoxList projectCategoryList;
protected void Page_Load(object sender, EventArgs e)
{
String connectionString = WebConfigurationManager.ConnectionStrings ["BSCDB"].ConnectionString;
m_DataAccessLayer = new EAReportingDAL(connectionString);
LoadUserPreferences();
}
protected void btnSavePref_Click(object sender, EventArgs e)
{
string userName = this.Page.User.Identity.Name;
DataSet availabeData = m_DataAccessLayer.GetUserPreferences(this.Page.User.Identity.Name, Constants.ProjectsUIView);
}
}
in the button click event handler btnSavePref_Click() the the db connection object m_DataAccessLayer is always null, but whereas the same object in LoadUserPreferences() [which i haven't pasted here though] works fine! plz guide me where im wrong or if someone needs more details!!
I'm not very familiar with UpdatePanel mechanics but maybe you defined it in such a way that it bypass the Page_Load method.
What I suggest is moving the code create the data access layer to separate method then calling this method from both the page load and button click handler:
private void InitDataAccess()
{
//ignore if already created
if (m_DataAccessLayer != null)
return;
String connectionString = WebConfigurationManager.ConnectionStrings ["BSCDB"].ConnectionString;
m_DataAccessLayer = new EAReportingDAL(connectionString);
LoadUserPreferences();
}
protected void Page_Load(object sender, EventArgs e)
{
InitDataAccess();
}
protected void btnSavePref_Click(object sender, EventArgs e)
{
InitDataAccess();
string userName = this.Page.User.Identity.Name;
DataSet availabeData = m_DataAccessLayer.GetUserPreferences(this.Page.User.Identity.Name, Constants.ProjectsUIView);
}
Very famous error message (see below), judging by the number of Google results. But every one of them I've seen suggests to set EnableEventValidation to false. I have searched my entire codebase, and I cannot find the string "EnableEventValidation" anywhere. Moreover, this code used to work; something I have done has obviously broken the pages. But what?
The error happens when I click on a button inside a Telerik RadGrid, declared as:
<telerik:RadGrid ID="MyGrid" Width="100%" ItemStyle-BorderColor="Gainsboro"
ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="1px" ActiveItemStyle-BackColor="Bisque"
SelectedItemStyle-BackColor="Black" AllowPaging="True" PageSize="15" runat="server"
AllowSorting="true" OnItemCommand="MyGrid_ItemCommand" AutoGenerateColumns="false"
OnNeedDataSource="MyGrid_NeedDataSource" GridLines="Horizontal" AllowMultiRowSelection="false"
Skin="Black">
<GroupingSettings CaseSensitive="false" />
<MasterTableView Width="100%" DataKeyNames="ID" AllowFilteringByColumn="false" Font-Names="Arial"
Font-Size="10px">
<Columns>
<telerik:GridButtonColumn ButtonType="PushButton" Text="Cancel" CommandName="Cancel"
ConfirmText="Are you sure you want to cancel this?">
</telerik:GridButtonColumn>
...
</Columns>
</MasterTableView>
<PagerStyle Mode="NextPrevAndNumeric" />
<FilterMenu EnableTheming="True">
<CollapseAnimation Duration="200" Type="OutQuint" />
</FilterMenu>
</telerik:RadGrid>
click on the "Cancel" button, and here's the famous error:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
Here's the problem: in my Page_Load method I had:
protected void Page_Load(object sender, EventArgs e) {
MyGrid.Rebind();
}
The rebinding of the grid on postback was obviously screwing something up. I changed it to:
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
MyGrid.Rebind();
}
}
and everything is working now.
I had the same problem but I had no Grid.Rebind() or Grid.Databind() in my NeedDataSource method or Page_Load method. This happened just after I drag a column to be grouped and then order the grouped column ASC/DESC
I simply added
EnableEventValidation="false"
in the <%# Page %> tag of my .aspx page. The ordering fails but at least I no longer get the error. As a note everything else works perfectly except the ordering of a grouped column
here is the code I use in the NeedDataSource method
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
String connstr = ConfigurationManager.ConnectionStrings["PrimeIntegartionsConnectionString"].ConnectionString;
SqlDataSource Ds = new SqlDataSource(connstr, BuildSql()); //buildsql simply returns a SQLSelect String "select * from example"
RadGrid1.DataSource = Ds;
}
Its very simple and i feel myself as an idiot :(
I newly started to using DevX Controls. Its documentation and sample projects are SUCKS!
My problem is:
I have an ASPxGridView on my aspx page:
<dx:ASPxGridView ID="dxdgMyGrid" runat="server" AutoGenerateColumns="False" OnStartRowEditing="DxGridStartRowEditing">
<SettingsEditing Mode="PopupEditForm" PopupEditFormHeight="200px" PopupEditFormWidth="500px"
EditFormColumnCount="2" PopupEditFormHorizontalAlign="Center" PopupEditFormVerticalAlign="Middle"
PopupEditFormModal="true" />
<Columns>
<dx:GridViewDataTextColumn FieldName="MyField1" VisibleIndex="1">
<EditFormSettings VisibleIndex="0" />
<EditItemTemplate>
<dx:ASPxDateEdit ID="dxdateMyField1" runat="server">
</dx:ASPxDateEdit>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
<dx:GridViewDataColumn FieldName="MyField2" VisibleIndex="4">
<EditFormSettings VisibleIndex="1" />
<EditItemTemplate>
<dx:ASPxComboBox ID="dxcomboMyField2" runat="server">
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataColumn>
</Columns>
How can i reach dxdateMyField1 or dxcomboMyfield2 on ASPX.CS file? I want to write:
dxcomboMyField2.DataSource = GetMyData2List();
dxcomboMyField2.SelectedItemIndex = 0;
... etc.
Thanks a lot.
You cannot access the EditItemTemplate Control Directly. You can access them at the HtmlRowCreated event as:
if (e.RowType != GridViewRowType.InlineEdit) return;
ASPxTextBox txtBox = ASPxGridView1.FindEditRowCellTemplateControl(ASPxGridView1.Columns["Name"]
as GridViewDataColumn, "ASPxTextBox1") as ASPxTextBox;
Check the documentation on Accessing Controls Contained within Templates
It is possible to cast the ASPxLabel.NamingContainer property to GridViewEditItemTemplateContainer and get a column value via the GridViewEditItemTemplateContainer.Text property.
But I like the technique of using the Init/Load event handler.When the grid switches to edit mode, the ASPxLabel.Load event is raised. Check this article The general technique of using the Init/Load event handler for implementation help.
[ASPx]
<dxe:ASPxTextBox ID="txtName" runat="server" Width="170px" OnInit="txtName_Init">
</dxe:ASPxTextBox>
[C#]
ASPxTextBox txtName;
protected void txtName_Init(object sender, EventArgs e)
{
txtName = (ASPxTextBox)sender;
GridViewEditFormTemplateContainer container = txtName.NamingContainer as GridViewEditFormTemplateContainer;
// You can remove the if statement, and try to insert a new record. You'll catch an exception, because the DataBinder returns null reference
if (!container.Grid.IsNewRowEditing)
txtName.Text = DataBinder.Eval(container.DataItem, "CategoryName").ToString();
}
Update Event:
protected void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
{
e.NewValues["CategoryName"] = txtName.Text;
}
There is already an question - ASPxGridView - How to find a control inside the EditItemTemplate on DevExpress fourm .
You can use combo box init/load event handler for setting combo datasource. If that doesn't work for you, use FindEditRowCellTemplateControl (use link in comments for further explanation).
Note: This question has been completely modified now that I have a simpler example.
I have set up a sample page which only has a ListView and ObjectDataSource. The first time the page comes up (!IsPostBack), my GetList method is called once. After paging (IsPostBack), the GetList method is called twice--the first time with the old paging values and the second time with the new values.
If I set EnableViewState="true" on the ListView, then the GetList method is only called once. It seems to me that the ListView wants an "initial state", which it either gets from ViewState or by re-running the method.
Is there any way to disable ViewState on the ListView and also prevent SelectMethod from being called twice?
ASPX page:
<asp:ListView ID="TestListView" runat="server" DataSourceID="ODS" EnableViewState="false">
<LayoutTemplate>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server" />
<asp:DataPager ID="TestPager" runat="server" PageSize="10">
<Fields>
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
</LayoutTemplate>
<ItemTemplate>
<div><%# Eval("Title") %></div>
</ItemTemplate>
</asp:ListView>
<asp:ObjectDataSource ID="ODS" runat="server" SelectMethod="GetList" SelectCountMethod="GetListCount"
TypeName="Website.Test" EnablePaging="true" />
ASPX code-behind:
namespace Website
{
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public IList<DataItem> GetList(int maximumRows, int startRowIndex)
{
return GetListEnumerable().Skip(startRowIndex).Take(maximumRows).ToList();
}
public IEnumerable<DataItem> GetListEnumerable()
{
for (int i = 0; i < 100; i++)
{
yield return new DataItem { Title = i.ToString() };
}
}
public int GetListCount()
{
return 100;
}
}
public class DataItem
{
public string Title { get; set; }
}
}
Either turn ODS caching on.
<asp:ObjectDataSource ID="ODS" ... EnableCaching="true" />
This way the GetList will be called only when new data is needed. Post backs to pages that already had data retrieved will use the cached version and not call the GetList.
Or move your DataPager out of the ListView and set the PagedControlID property.
Actually you should be using the OnSelecting event.
What happens is that ObjectDataSource calls the method SelectMethod twice
First time it gets the data.
Next time it gets the count.
So I think you have to implement the OnSelecting event
<asp:ObjectDataSource ID="ODS" runat="server" SelectMethod="GetList" SelectCountMethod="GetListCount"
OnSelecting="ods_Selecting">
TypeName="Website.Test" EnablePaging="true" />
and then cancel the event when the ObjectDataSource tries to call the count method.
protected void ods_Selecting(object sender,
ObjectDataSourceSelectingEventArgs e)
{
if (e.ExecutingSelectCount)
{
//Cancel the event
return;
}
}
You can look for full implementation as mentioned in the link below
http://www.unboxedsolutions.com/sean/archive/2005/12/28/818.aspx
Hope this helps.
I had a similar problem where it worked different depending on browser. IE one way and all other browsers one way.. Might not be the same issue as you have.
I solved it this way:
protected void DropDownDataBound(object sender, EventArgs e)
{
// Issue with IE - Disable ViewState for IE browsers otherwhise the dropdown will render empty.
DropDownList DDL = (DropDownList)sender;
if (Request.Browser.Browser.Equals("IE", StringComparison.CurrentCultureIgnoreCase))
DDL.ViewStateMode = System.Web.UI.ViewStateMode.Disabled;
else
DDL.ViewStateMode = System.Web.UI.ViewStateMode.Inherit;
}