Im new to ASP C# and I just want to ask on what is wrong on my code. It is going on the SelectedIndexChanged but not updating the visibility of my <tr>
Here is my ClientSide code
<tr id="trList2" runat="server" visible="false">
<td>
<asp:Label ID="lblList" AssociatedControlID="rcbList" runat="server" Text="Car List:" />
</td>
<td>
<telerik:RadComboBox ID="rcbList" runat="server" Skin="Sunset" Width="400px" DataTextField="car_name"
DataValueField="car_id" AppendDataBoundItems="true"
OnSelectedIndexChanged="rcbList_SelectedIndexChanged" AutoPostBack="true" >
<Items>
<telerik:RadComboBoxItem Value="0" Text="[Select Project]" />
</Items>
</telerik:RadComboBox>
</td>
</tr>
<tr id="trList4" runat="server" visible="false">
<td>
<asp:Label runat="server" AssociatedControlID="chkIsOpen">Check if Open</asp:Label>
</td>
<td>
<asp:CheckBox runat="server" ID="chkIsOpen" OnCheckedChanged="IsOpen_CheckedChange" AutoPostBack="true" />
</td>
</tr>
Here is my Server Side:
protected void rcbList_SelectedIndexChanged(object sender, EventArgs e)
{
var checkVal = rcbList.SelectedIndex;
if (rcbList.SelectedValue != "0")
{
trList4.Visible = false;
}
else
{
trList4.Visible = true;
}
}
im getting the error
Uncaught Sys.InvalidOperationException: Sys.InvalidOperationException: Could not find UpdatePanel with ID "xxx". If it is being updated dynamically then it must be inside another UpdatePanel in browser element but I dont have any updatepanel in my Page
Related
I have created an aspx page in which I want some controls to be enabled on basis of user selection.
If user selects All two radio buttons should be enabled, hide otherwise.
My declarative part is:
<tr>
<td>
<asp:Label ID="lblCommunityMembers" runat="server" Text="Community Members" />
</td>
<td>
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="upCommunityMembers" runat="server">
<ContentTemplate>
<asp:RadioButton ID="rdbCommunityMembersAll" runat="server" Text="All" GroupName="grpCommMembers" Checked="true" OnCheckedChanged="rdbCommunityMembersAll_CheckedChanged" AutoPostBack="true" />
<asp:RadioButton ID="rdbCommunityMembersSelectedUsers" runat="server" Text="Selected Users" GroupName="grpCommMembers" OnCheckedChanged="rdbCommunityMembersSelectedUsers_CheckedChanged" AutoPostBack="true" />
<SharePoint:ClientPeoplePicker ID="ppCommunityMembers" runat="server" AllowMultipleEntities="true" AllowEmpty="false" Visible="false" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCommunityCatagory" runat="server" Text="Community Catagory" />
</td>
<td>
<asp:DropDownList ID="ddlCommunityCatagory" runat="server">
<asp:ListItem Value="0">---- Select One ----</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvCommunityCatagory" runat="server" InitialValue="0" ErrorMessage="Please Select Community Catagory"
ForeColor="Red" ControlToValidate="ddlCommunityCatagory" Display="Dynamic" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblCommunityAccess" runat="server" Text="Required Approval?" Visible="false" />
</td>
<td>
<asp:RadioButton ID="rdbRequiredApprovalYes" runat="server" Text="Yes" GroupName="grpCommMembers" Checked="true" Visible="false" />
<asp:RadioButton ID="rdbRequiredApprovalNo" runat="server" Text="No" GroupName="grpCommMembers" Visible="false"/>
</td>
</tr>
My code behind:
protected void rdbCommunityMembersSelectedUsers_CheckedChanged(object sender, EventArgs e)
{
if (rdbCommunityMembersSelectedUsers.Checked)
{
enableControls();
}
else
{
disableControls();
}
}
protected void rdbCommunityMembersAll_CheckedChanged(object sender, EventArgs e)
{
if (rdbCommunityMembersAll.Checked)
{
disableControls();
}
else
{
enableControls();
}
}
protected void enableControls()
{
ppCommunityMembers.Visible = true;
lblCommunityAccess.Visible = true;
rdbRequiredApprovalNo.Visible = true;
rdbRequiredApprovalYes.Visible = true;
}
protected void disableControls()
{
ppCommunityMembers.Visible = false;
lblCommunityAccess.Visible = false;
rdbRequiredApprovalNo.Visible = false;
rdbRequiredApprovalYes.Visible = false;
}
If Community members are selected to all then "Required Approval?" part should get hidden.
But problem is when I select selected users then I am getting only people picker control visible, the required approval contorls are not getting displayed. What am I missing?
Your Radio Buttons rdbCommunityMembersAll and rdbCommunityMembersSelectedUsers are inside update panel, thus they are doing partial postback. To make the control visible outside the UpdatePanel you can do any one of the following:
Move rdbCommunityMembersAll and rdbCommunityMembersSelectedUsers
outside the UpdatePanel
Move the controls you need to make visible
(lblCommunityAccess, rdbRequiredApprovalNo, rdbRequiredApprovalYes)
inside UpdatePanel
Or
Instead of setting Visible="false", set style="display:none" and
trigger the visibility through javascript/jquery
I've a problem with ModalPopupExtender. I have put a label in ModalPopupExtender and trying to bind label with the value from database. When I am debugging, the value is showing on the label's text (ie there is no database error), but it is not displaying when the popup window is shown.
Can any one help me please ????????
Here's my code
Code on html
<asp:Panel ID="PopupPnl" runat="server">
<table style="width:100%;">
<tr>
<td >
<asp:Label ID="Label2" runat="server"
Text="View Description" >
</asp:Label>
</td>
</tr>
<tr>
<td >
<asp:Label ID="label_Descrption" runat="server" >
</asp:Label>
</td>
</tr>
<tr style="background-color:White;">
<td >
<asp:Button ID="btnExit" runat="server" Text="Exit"/>
</td>
</tr>
</table>
</asp:Panel>
<asp:Button ID="btnShowPopup" runat="server"
style="display:none;"/>
<cc1:ModalPopupExtender ID="ModalPopupExtender2" runat="server"
TargetControlID="btnShowPopup"
PopupControlID="PopupPnl"
CancelControlID="btnExit"
BackgroundCssClass="ModalPopupBG" >
</cc1:ModalPopupExtender>
Code on c#
protected void lbn_Template_Click(object sender, EventArgs e)
{
util_Category objUtilCategory = new util_Category();
cl_Category objClCategory = new cl_Category();
if (ddlSubCategory.SelectedItem.Text != "--Select A SubCategory--")
{
objClCategory.CategoryId = Convert.ToInt32(ddlSubCategory.SelectedValue);
Label lbl = (Label)PopupPnl.FindControl("label_Descrption");
label_Descrption.Text = objUtilCategory.GetATemplate(objClCategory);
ModalPopupExtender2.Show();
}
}
You need to place the Panel which contains the label_Description inside UpdatePanel.
So i have the following method
protected void isDirector_CheckedChanged(object sender, EventArgs e)
{
HtmlTableRow row = (HtmlTableRow)e.Item.FindControl("today");
But getting error
CS0117: 'System.EventArgs' does not contain a definition for 'Item'
EDIT :
<asp:UpdatePanel ID="UpdatePanel2"
runat="server"
UpdateMode="Conditional">
<ContentTemplate>
<asp:RadioButtonList ID="isDirector" RepeatDirection="Horizontal" runat="server" AutoPostBack="True" OnSelectedIndexChanged="isDirector_CheckedChanged">
<asp:ListItem Text="Yes" Value="True" selected></asp:ListItem>
<asp:ListItem Text="No" Value="False"></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel
<ContentTemplate>
<tr runat="server" id="test">
<td>Director First Name:</td>
<td><asp:TextBox ID="DirectorfirstNametxt" runat="server" MaxLength="100" CssClass="input"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" Display="None" runat="server"
ErrorMessage="Director First Name is required." ControlToValidate="DirectorfirstNametxt"></asp:RequiredFieldValidator>
</td>
</tr>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="isDirector" EventName="SelectedIndexChanged" />
</Triggers>
I am trying to change the CSS CLASS of TR ID = "test"
Assuming you have your Checkboxes inside of a HTML-TableRow and you want to set the CSS-Class of the TR in the CheckedChanged-Event:
This is an example(note that the TR's have a runat="server"-tag):
<table>
<tr ID="TR1" runat="server">
<td>
<asp:CheckBox ID="CheckBox1" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
<tr ID="TR2" runat="server">
<td>
<asp:CheckBox ID="CheckBox2" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
<tr ID="test" runat="server">
<td>
<asp:CheckBox ID="CheckBox3" OnCheckedChanged="isDirector_CheckedChanged" AutoPostBack="true" runat="server" />
</td>
</tr>
</table>
and this is the codebehind:
protected void isDirector_CheckedChanged(object sender, EventArgs e)
{
//var row = (HtmlTableRow)((CheckBox)sender).Parent.Parent;
test.Attributes("class") = "CssClass";
}
Edit: if your tr's are runat="server" and they have unique ID's, you can access them directly
What kind of control is isDirector_CheckChanged tied to - a checkbox?
As the error says, EventArgs is the type of event you're expecting and it doesn't have an 'Item' property. Maybe you're thinking of GridView, Repeater, or other 'item-like' controls?
I'm guessing you're trying to handle the changed event of a checkbox you've put in a repeating/table control. If so, you'll need to handle a Selected or similar event for the repeater that DOES use an EventArgs-derived type with an Item property.
I have Datalist that is inside an updatepanel and it is in panel in modalpopupextender;
I can list items as I wanted. I am also putting 2 buttons for Delete and AddBelow. Here is the markup:
<asp:DataList ID="SpeedDialsDL" runat="server">
<ItemTemplate>
<table id="speedDialValueEditorTable" width="100%">
<tr>
<td width="275px">
<asp:Label ID="ValueLabel" runat="server" Text="Value"></asp:Label>
</td>
<td>
<asp:TextBox ID="ValueTextBox" runat="server" Text='<%# Eval("Value") %>' Width="340px"
Enabled="false"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Delete" runat="server" Text="Delete" CommandName="Delete"
CausesValidation="false" />
<asp:Button ID="AddNewButton" runat="server" Text="AddBelow" CommandName="AddBelow"
CausesValidation="false" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
And register evenst like following: (I have used both ItemCommand and DeleteCommand to see which works:)
protected void Page_Load(object sender, EventArgs e)
{
SpeedDialsDL.ItemCommand += SpeedDialsDL_ItemCommand;
SpeedDialsDL.DeleteCommand += SpeedDialsDL_ItemCommand;
}
void SpeedDialsDL_ItemCommand(object source, DataListCommandEventArgs e)
{
switch (e.CommandName)
{
case "Delete":
this.DeleteFromList((string)e.CommandArgument);
break;
case "AddBelow":
break;
}
}
But when I click Delete Or AddBelow buttons I get following 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.
I have disabled eventvalidation of page but the event couldn't be caught...
What am I missing here?
A control registers its events during rendering and then validates the events during the post-back or callback handling. You're registering the events manually during Page_Load.
Try refactoring your code so you specify the event handler in the .aspx page, bind the item's Id to the button's CommandArgument, then get the bound item Id in the handler. I would also have separate event handlers for the different events, it's a little cleaner. Something like:
<asp:DataList ID="SpeedDialsDL" runat="server">
<ItemTemplate>
<table id="speedDialValueEditorTable" width="100%">
<tr>
<td width="275px">
<asp:Label ID="ValueLabel" runat="server" Text="Value"></asp:Label>
</td>
<td>
<asp:TextBox ID="ValueTextBox" runat="server" Text='<%# Eval("Value") %>' Width="340px" Enabled="false"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="Delete" runat="server" Text="Delete" OnClick="Delete" CausesValidation="false" CommandArgument='<%# Eval("Id") %>' />
<asp:Button ID="AddNewButton" runat="server" Text="AddBelow" OnClick="AddBelow" CausesValidation="false" CommandArgument='<%# Eval("Id") %>' />
</td>
</tr>
</table>
</ItemTemplate>
protected void Delete(object sender, EventArgs e)
{
Button b = (Button)sender as Button;
string boundItemId = b.CommandArgument;
//handle delete
}
protected void AddBelow(object sender, EventArgs e)
{
Button b = (Button)sender as Button;
string boundItemId = b.CommandArgument;
//handle add below
}
I am working with the listview control. By default I am showing the itemtemplate with an edit button. When the edit button is pressed the listview switches to the edititemtemplate. I need to populate one of the controls in the edititemtemplate based on the item being edited - I've tried accessing the control (via FindControl) in the ItemEditing event (and pretty much every other event as well), however the controls just don't seem to exist. I can access controls in the itemtemplate ok, but not the edititemtemplate.
Can anyone let me know how I can access a control held within the edititemtemplate of a listview, and from which event I should do so?
EDIT
I'm trying to access the control using this:
protected void UnitsLV_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListViewItem item = UnitsLV.Items[e.NewEditIndex];
ListBox tempLB = (ListBox)e.item.FindControl("ListBox3");
}
I've also tried in ItemDataBound and ItemCreated.
The listview declaration is:
<asp:Content ID="Content1" ContentPlaceHolderID="ColumnA" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="SummaryPnl" runat="server">
<asp:ListView ID="UnitsLV" runat="server" DataSourceID="DataLDS" DataKeyNames="u_uid"
InsertItemPosition="LastItem" OnItemInserting="UnitsLV_ItemInserting" OnItemDataBound="UnitsLV_ItemDataBound"
OnItemCreated="UnitsLV_ItemCreated" onitemediting="UnitsLV_ItemEditing">
<ItemTemplate>
<tr class="rowA">
<td>
<asp:Label runat="server" ID="UnitIDLbl" Text='<%# Eval("u_uid")%>'></asp:Label>
</td>
<td>
<%# Eval("u_Title")%>
</td>
<td>
<asp:LinkButton ID="EditBtn" runat="server" CommandName="Edit" CommandArgument='<%#Eval("u_uid") %>'
Text="Edit" />
</td>
<td>
<asp:LinkButton ID="DeleteBtn" runat="server" CommandName="Delete" CommandArgument='<%#Eval("u_uid") %>'
Text="Delete" />
</td>
</tr>
</ItemTemplate>
<InsertItemTemplate>
<tr class="rowB">
<td>
<br />
</td>
<td>
<br />
<asp:TextBox ID="TitleTB" runat="server" Text='<% #Bind("u_Title")%>'></asp:TextBox>
</td>
<td>
<br />
<asp:ListBox ID="ListBox3" runat="server"></asp:ListBox>
<asp:ListBox ID="ToBeDeletedLB" runat="server"></asp:ListBox>
</td>
<td>
<asp:LinkButton ID="InsertBtn" runat="server" CommandName="Insert" Text="Insert" />
</td>
<td>
<asp:LinkButton ID="CancelBtn" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</InsertItemTemplate>
<EditItemTemplate>
<tr class="rowB">
<td>
<br />
<asp:Label runat="server" ID="UnitIDLbl" Text='<%# Bind("u_uid")%>'></asp:Label>
</td>
<td>
<br />
<asp:TextBox ID="TitleTB" runat="server" Text='<% #Bind("u_Title")%>'></asp:TextBox>
</td>
<td>
<br />
<asp:ListBox ID="ListBox3" runat="server"></asp:ListBox>
<asp:ListBox ID="ToBeDeletedLB" runat="server"></asp:ListBox>
</td>
<td>
<asp:LinkButton ID="UpdateBtn" runat="server" CommandName="Update" Text="Update" />
</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</EditItemTemplate>
<LayoutTemplate>
<table id="Table2" runat="server" width="100%">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="" width="100%">
<tr id="itemPlaceholder" runat="server"></tr>
</table>
</td>
</tr>
<tr id="Tr2" runat="server">
<td id="Td2" runat="server" style=""></td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</asp:Content>
EDIT:
I've iterated over all the controls in the listview using code similar to below, and the control is still not visible. Does the ItemEditing event fire before the edit template is shown? If so, what event can I use to access the edit template controls?
foreach (Control child in control.Controls)
{
Control result = Find(child, id);
if (result != null)
{
return result;
}
}
**EDIT: **
I can access the controls in the edititemtemplate in the listview's ItemCreated event, however none they have no content (I'd assume the data hasn't been bound yet), so I can't get the key-value I need to do a lookup to get the data I need to populate the control.
I've figured out a way to do what I need to do, though I'm not terribly happy with it.
protected void UnitsLV_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (UnitsLV.EditIndex > -1)
{
// Controls within the edititemtemplate are available via e.Item.FindControl("controlname")
}
}
I don't know about previous editions but in Visual Studio 2010 you can easily access the edit item trhough the "ListView.EditItem" property like this:
private void myListView_ItemEditing(object sender, ListViewEditEventArgs e)
{
myListView.EditIndex = e.NewEditIndex;
myListView.DataBind();
ListViewItem lvwItem = lvwLista.EditItem;
ListBox tempLB = (ListBox) lvwItem.FindControl("ListBox3");
}
protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
ListBox myListBox = (ListBox)(((ListView)sender).EditItem.FindControl("ListBox1"));
}
protected void UnitsLV_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListViewItem item = UnitsLV.Items[e.NewEditIndex];
ListBox tempLB = (ListBox)e.item.FindControl("ListBox3");
}
I believe I found a typo in the above function. The second line should be
ListBox tempLB = (ListBox)item.FindControl("ListBox3");
What I did was replace "e.item" with "item"
I usually use the ItemDataBound Event... check the other options in ListItemType Enum
protected void UnitLV_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem)
{
ListBox myListBox = (ListBox) e.Item.FindControl("ListBox3");
}
}
this is similar to the accepted answer, but I think its author was really driving towards this:
protected void UnitsLV_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem listViewDataItem = e.Item as ListViewDataItem;
if (UnitsLV.EditIndex == listViewDataItem.DataItemIndex)
{
// Controls within the edititemtemplate are available via e.Item.FindControl("controlname")
}
}