I have a RadListView and within the listview I have an asp.net linkbutton. I want to dynamically set the linkbutton's PostBackUrl. I can achieve this if I find the linkbutton control in the listview's ItemDataBound event. But by doing this when I end up clicking on the linkbutton the listview ItemCommand event is not being fired. I need the itemCommand event to be fired so I can take the datakeyvalue of the item clicked and set it into a session variable to pass to the postbackurl page of the link button, but setting the postbackurl when the page loads causes the linkbutton not to fire any events.
<telerik:RadListView ID="lstVwWebpageList" runat="server" EnableViewState="true" ItemPlaceholderID="webpageContainer" AllowPaging="true" DataKeyNames="id" Skin="WebBlue" OnItemDataBound="lstVwWebpageList_ItemDataBound" OnPageIndexChanged="lstVwWebpageList_PageChange" Width="607px" OnItemCommand="lstVwWebpageList_ItemCommand">
<LayoutTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:PlaceHolder ID="webpageContainer" runat="server" />
</td>
</tr>
<tr>
<td>
<telerik:RadDataPager ID="Pager" runat="server" PagedControlID="lstVwWebpageList" PageSize="50" Skin="WebBlue">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" />
<telerik:RadDataPagerButtonField FieldType="Numeric" />
<telerik:RadDataPagerButtonField FieldType="NextLast" />
</Fields>
</telerik:RadDataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<fieldset style="float: left; width: 300px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="width: 25%;">
<b>Name:</b>
</td>
<td style="width: 75%;">
<asp:Label ID="lblName" runat="server" Text='<%# Eval("name") %>'></asp:Label>
</td>
</tr>
<tr>
<td style="width: 25%;">
<b>Page:</b>
</td>
<td style="width: 75%;">
<asp:LinkButton ID="pagenameLink" runat="server" OnClick="test" OnCommand="testing" CommandName="LinkClicked" Text='<%# Eval("pagename") %>' PostBackUrl='<%# "EditWebpage.aspx?name=" + Eval("name") + "&page=" + Eval("pagename") %>'></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
</fieldset>
</ItemTemplate>
protected void lstVwWebpageList_ItemCommand(object sender, RadListViewCommandEventArgs e)
{
if (e.CommandName == "LinkClicked")
{
RadListViewDataItem item = (RadListViewDataItem)e.ListViewItem;
Session["linkID"] = item.DataItem;
}
}
try this
<asp:LinkButton runat="server"
ID="pagenameLink"
Text='<%# Eval("pagename") %>'
CommandName="LinkClicked"
CommandArgument='<%#Eval("name") + ", " + Eval("pagename") %>' />
Related
LinkButton OnClick(LoadDocumentVersion) is Not Frie inside Update panal here is my Code in aspx page I tried using UpdateMode="Conditional" it is not fire and asyncpostback also used it is not fire
<pre>LinkButton OnClick(LoadDocumentVersion) is Not Frie inside Update panal
</pre>
<asp:UpdatePanel ID="Aspx_UpdatePanel_DocumentVersion" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:LinkButton ID="Aspx_LinkButton_DocumentVersion" runat="server" Style="float: right; margin: 2px 5px 2px 0;" CssClass="Label_Text9"
OnClick="LoadDocumentVersion" />
<asp:UpdateProgress runat="server" AssociatedUpdatePanelID="Aspx_UpdatePanel_DocumentVersion"
DynamicLayout="true">
<ProgressTemplate>
<img src="Images/loading.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center" style="float: left;">
<tr valign="top">
<td style="padding: 5px;" align="center">
<asp:Repeater ID="Aspx_Repeater_DocumentVersions" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center">
<tr valign="top" align="left" class="border_spacing">
<td class="Heading_border_left_spacing">
<asp:Label ID="Label1" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_FileName %>" />
</td>
<td class="Heading_border_withoutspacing">
<asp:Label ID="Label2" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Type %>" />
</td>
<td class="Heading_border_withoutspacing">
<asp:Label ID="Label3" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Size %>" />
</td>
<td class="Heading_border_right_spacing">
<asp:Label ID="Label4" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Created_By %>" />
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr valign="middle" align="left" height="25px">
<td class="border_left_spacing">
<a class="Anchor_Text9_Grey" href="DownloadAttachment.aspx?InternalPath=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalPath"].ToString () %>&InternalFileName=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalFileName"].ToString () %>&ExternalFileName=<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>"
onclick='javascript:SafeHandleURL(this, "DownloadAttachment.aspx", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalPath"].ToString ().Replace ( #"\", #"\\" ) %>", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["InternalFileName"].ToString () %>", "<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>" );'>
<asp:Label ID="Label5" runat="server" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["ExternalFileName"].ToString () %>'
CssClass="Label_Text9" /> </a>
</td>
<td class="border_withoutspacing">
<asp:Label ID="Label6" runat="server" CssClass="Label_Text9" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["Type"].ToString () %>' />
</td>
<td class="border_withoutspacing Label_Text9">
<asp:Label ID="Label7" runat="server" CssClass="Label_Text9" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["FileSize"].ToString () %>' />
<asp:Label ID="Label8" runat="server" CssClass="Label_Text12_Bold" Text="<%$Resources:CRMDocument, Lbl_Attachments_Bytes %>" />
</td>
<td class="border_right_spacing">
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["CreatedBy"].ToString () %>'
CssClass="Label_Text9" CommandArgument='<%#( (System.Data.DataRowView)(Container.DataItem)).Row["CreatedByID"].ToString () %>'
OnCommand="GoToEmployee" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr height="10px">
<td colspan="3" />
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
CodeBehind.cs
protected void LoadDocumentVersion(object sender, EventArgs e)
{
try
{
string zszFolderID = "";
string zszDocumentID = "";
string zszIsPublic = "";
EMSBLCommon.AddToLog("Document", "CRM", "View Document Versions", "");
string zszUpdateDocument = Aspx_HiddenField_DocumentPath.Value;
string zszDocumentPath = zszUpdateDocument.Substring(0, zszUpdateDocument.LastIndexOf('/'));
string zszDocumentName = zszUpdateDocument.Substring(zszUpdateDocument.LastIndexOf('/') + 1);
zszFolderID = GetFolderID(zszDocumentPath, ref zszIsPublic);
zszDocumentID = EMSBLCRM.GetDocumentID(zszFolderID, zszDocumentName).ToString();
if (!zszDocumentID.Equals("0"))
LoadDocumentAttachments(zszDocumentID);
}
catch (Exception ex)
{
Utilities.SendCrashEMail(ref ex);
}
}
Make sure AutoEventWireup="true" in your Page directive
Make sure you do not get errors, either client-side or server-side. Attach a debugger and step through your code to make sure of that
Your button cannot be clicked as it is because it is invisible, so I assume you invoke the click via JavaScript. To do that for a link button, you need to evaluate its href attribute: eval(document.getElementById("<%=Aspx_LinkButton_DocumentVersion.ClientID%>").getAttribute("href"));
make sure all webresource requests pass (i.e., 200 or 300s status codes). This is how the MS AJAX frameworks is fetched.
Make sure your script manager is the first control after the <form> tag and that all subsequent AJAX-enabled stuff is inside the <form> as well.
On chkSubModuleView_CheckedChanged() event iwant to get the id of chkModule.Please tell me how to get the id or reference of parent checkbox on click of child checkbox in server side.How to distinguish between different modules .
enter code here
<asp:ListView ID="lvModule" runat="server">
<LayoutTemplate>
<table width="600px" border="0" cellpadding="0" cellspacing="0"
class="ListViewtable">
<tr>
<th style="width: 10%;">
Modules
</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder" runat="server">
</asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkModule" runat="server"
CausesValidation="false" AutoPostBack="true"
OnCheckedChanged="chkModule_CheckedChanged" >
</asp:CheckBox><asp:HiddenField ID="hfEntityName"
Value='<%# Eval("EntityName") %>' runat="server" />
<%# Eval("Title")%>
<asp:HiddenField ID="hfID" Value='<%# Eval("ID") %>'
runat="server" />
<asp:Label ID="label" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td colspan="2" style="padding-left: 20px;">
<asp:ListView ID="lvSubModule" runat="server">
<LayoutTemplate>
<table width="100%" cellspacing="0" border="0"
class="ListViewtableLayer2">
<tr>
<th style="width: 20%;">
Sub Module
</th>
<th style="width: 20%;">
<asp:CheckBox ID="chkSubModuleView"
Checked="true" runat="server" AutoPostBack="true"
OnCheckedChanged="chkSubModuleView_CheckedChanged" />
View
</th>
</tr>
<asp:PlaceHolder ID="itemPlaceholder"
runat="server"></asp:PlaceHolder>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("Title")%>
<asp:HiddenField ID="hfMenuID" Value='<%#
Eval("MenuID") %>' runat="server" />
<asp:HiddenField ID="hfName" Value='<%#
Eval("HeaderID") %>' runat="server" />
</td>
<td>
<asp:CheckBox ID="chkRead" runat="server"
AutoPostBack="true" Checked="true" CausesValidation="false"
OnCheckedChanged="chkRead_CheckedChanged"></asp:CheckBox>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
change your checkbox property to
<asp:CheckBox ID="chkSubModuleView"
Checked="true" runat="server" AutoPostBack="true" Key='<%# Eval("ID")%>'
OnCheckedChanged="chkSubModuleView_CheckedChanged" />
In your .cs
protected void chkSubModuleView_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
string yourID = chk.Attributes["Key"].ToString();
}
I have a List of Client Displayed in Repeater. I have a Details Button in Repeater which displays the Details of Client when Clicked. For Sample now just added 'ClientName' only. *When i Click on 'Details' LinkButton in Repeater it Displays the Details of Selected Row. But, this causes FullPage Post Back! Which i want to Prevent. Just i want to Update the Panel which displays the Details when row is selected from Repeater*.
In .aspx page:
<script>
function ShowPopUp() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "block";
}
function ClosePopup() {
var listItemsRegion = document.getElementById('popup');
popup.style.display = "none";
}
</script>
<asp:Repeater ID="RepDetails" runat="server" OnItemCommand="RepDetails_ItemCommand">
<HeaderTemplate>
<table class="tabl">
<tr style="background-color: #808080; color: White">
<td class="lblCenter">
<asp:Label ID="Label4" runat="server" Text="City" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label3" runat="server" Text="Age" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label1" runat="server" Text="Gender" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:Label ID="Label5" runat="server" Text="Details" Font-Bold="true" CssClass="lbl"></asp:Label>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr class="<%# Container.ItemIndex % 2 == 0 ? "rowEven" : "rowOdd" %>">
<td class="lblCenter">
<asp:Label ID="lblCity" runat="server" Text='<%#Eval("City") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblAge" runat="server" Text='<%#Eval("Age") %>' /></td>
<td class="lblCenter">
<asp:Label ID="lblGen" runat="server" Text='<%#Eval("Gender") %>' CssClass="lbl"></asp:Label>
</td>
<td class="lblCenter">
<asp:LinkButton ID="lblDetails" runat="server" CommandName="Display"
CommandArgument='<%#Eval("ID") %>'>Details</asp:LinkButton></td>
<asp:Label ID="rlblClientname" runat="server" Text='<%#Eval("Client") %>' Visible="false"></asp:Label>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<div id="popup" style="display: none">
<asp:UpdatePanel ID="UpdatePanel6" runat="server">
<ContentTemplate>
<table width="80%" align="center">
<tr>
<td> </td>
<td width="30%"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<asp:Label ID="Label15" runat="server" CssClass="lbl" Text="Client Code"></asp:Label>
</td>
<td>
<asp:Label ID="lblClientName" runat="server" CssClass="lbl"></asp:Label>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>
<input id="Button2" type="button" value="Close" onclick="ClosePopup();" class="but" /> </td>
</tr>
</table>
</ContentTemplate>
<%-- <Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="RepDetails_ItemCommand" />
</Triggers>--%>
</asp:UpdatePanel>
</div>
In Repeater Item Command:
protected void RepDetails_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Display")
{
LinkButton lblDetails = (LinkButton)e.Item.FindControl("lblDetails");
Label rlblClientname = (Label)e.Item.FindControl("rlblClientname");
if (lblDetails != null && e.CommandArgument != null)
{
string val = e.CommandArgument.ToString();
if (rlblClientname != null && rlblClientname.Text != string.Empty)
{
lblClientName.Text = rlblClientname.Text;
}
string scrpt = "ShowPopUp();";
Page.ClientScript.RegisterStartupScript(this.GetType(), "s", scrpt, true);
}
}
}
This causes Full Page Post Back Which i want to Prevent.Onclick of Repeater row the details must be displayed with AsynPostBack. When adding Trigger Event to 'popup' div then it say control could not be found
Help Appreciated!
Thanks!
You have one of two Options:
1) Uncomment this code and change EventName="RepDetails_ItemCommand" to EventName="ItemCommand"
<Triggers>
<asp:AsyncPostBackTrigger ControlID="RepDetails" EventName="ItemCommand" />
</Triggers>
2) Put the Repeater in the <ContentTemplate> of the UpdatePanel
I've got an Imagebutton in my listview, but then I can't type in my code (aspx.cs) in Imagebutton1.Click:
<asp:ListView ID="lvFotos" runat="server"
GroupItemCount="6" InsertItemPosition="LastItem" align="center">
<LayoutTemplate>
<table border="0">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td align="center" height="150px"
style="background-color: #ffffff;color: #ffffff; border:none;" width="142px">
<asp:ImageButton ID="ImageButton1" ImageUrl="<%# Container.DataItem %>" runat="server" Width="142" Height="142" />
</td>
</ItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
</asp:ListView>
How can I resolve this?
You shoul use listview ItemCommand event.
<asp:ImageButton ID="ImageButton1" ImageUrl="<%# Container.DataItem %>" runat="server" Width="142" Height="142" CommandName="Fire_click_event" />
public void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if(e.CommandName != "Fire_click_event")
{
// Do what you want in click event
}
}
I have a list view and i want to add a header row in it which will come when the listview has data or not. in each and every condition i want it there. I have used LayOut Template to do so but its showing the Header row only if the listview has data.Then i tried EmptydataTemplate, Its showing the header row but now the button in it is not working.
My code is
<asp:UpdatePanel ID="upViewSchedule" runat="server">
<ContentTemplate>
<asp:ListView ID="lstuser" runat="server" ItemPlaceholderID="trItem" DataKeyNames="id"
OnItemDataBound="lstuser_ItemDataBound">
<LayoutTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class='<%# Convert.ToBoolean(Container.DataItemIndex % 2) ? "OddRowColor" : "EvenRowColor" %>'>
<td align="left" width="138px">
<asp:DropDownList ID="drpname" runat="server" Width="120px">
</asp:DropDownList>
<asp:Label ID="lblCreatedBY" Text='<%# Eval("CreatedBy") %>' runat="server" Visible="false"></asp:Label>
<asp:Label ID="lblId" runat="server" Visible="false"></asp:Label>
<ajaxCtrl:CascadingDropDown ID="casddrpContacts" runat="server" TargetControlID="drpname"
Category="name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="Getuser">
</ajaxCtrl:CascadingDropDown>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("salary") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" width="138px">
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("address") %>' Width="110px"></asp:TextBox>
</td>
<td align="left" class="last">
<asp:ImageButton ID="imgBtnEdit" runat="server" ImageUrl="~/App_Themes/ThemeNew2/images/update.png"
CommandArgument='<%# Eval("id") %>' OnClick="imgBtnEdit_Click" ToolTip="Update user" />
<asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/delete.png"
CommandArgument='<%# Eval("id") %>' OnClientClick="return confirm('Are you sure you want to delete this user ?');"
ToolTip="Delete user" OnClick="imgBtnDelete_OnClick" />
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<table cellspacing="0">
<tr class="hdrRowColor1">
<td align="left">
name
</td>
<td align="left">
salary
</td>
<td align="left">
address
</td>
<td align="left" style="border-right: 1px solid #6398cc">
Actions
</td>
</tr>
<tr class="OddRowColor">
<td align="left">
<asp:DropDownList ID="drphdrname" runat="server" Width="120px">
</asp:DropDownList>
<ajaxCtrl:CascadingDropDown ID="csddrphdrName" runat="server" TargetControlID="drpname"
Category="Name" ServicePath="~/Resources/WebService.asmx" ServiceMethod="GetName">
</ajaxCtrl:CascadingDropDown>
</td>
<td>
<asp:TextBox ID="txtaddress" runat="server" Width="110px"></asp:TextBox>
</td>
<td width="50px" class="last">
<asp:ImageButton ID="imgBtnHdrAdd" runat="server" ImageUrl="~/App_Themes/ThemeNew/Images/add_new.png"
OnClick="imgBtnHdrAdd_Click" ToolTip="Add user." />
</td>
</tr>
<tr id="trItem" runat="server">
</tr>
</table>
</EmptyDataTemplate>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
my Code behind code is
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BIndAddress();
// BindRoleDrop();
drpAddress.Items.Insert(0, new ListItem("Select Area", ""));
drpRoom.Items.Insert(0, new ListItem("Select Room", ""));
ViewState["sortCol"] = "tblUser.id";
ViewState["sortDir"] = "Desc";
ViewState["nmbr"] = 1;
BindData(ViewState["sortCol"].ToString(), ViewState["sortDir"].ToString(), Convert.ToInt32(ViewState["nmbr"]), 7999);
}
else
{
lblMessage.Visible = false;
}
}
And one thing more please let me know how can i apply validations on these.
I did some testing locally. I found that if I have a button in the EmptyDataTemplate it's OnClick event will fire as expected as long as you do not modify the state of the ListView before the event fires.
I'm guessing therefore that you have some code that modifies the state (re-binds it for instance) of the ListView which runs before the imgBtnHdrAdd_Click event handler for the button in question.
The Page_Load method would have been the primary suspect, but based on your code it is properly checking for !IsPostBack.
I'm assuming that it is the call to BindData that is used for setting databinding the ListView. Look for other places in you code behind where that method is called and verify that none of those places are being run before the event handler for the button.