I have a strange issue in a datalist
<asp:DataList ID="dl" RepeatColumns="8" runat="server" GridLines="None" OnItemDataBound="dl_idb"
OnItemCommand="dl_ic" RepeatDirection="Horizontal">
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="margin-left: 15px; margin-right: 15px;">
<tr>
<td>
<li>
<asp:ImageButton ID="imgMat" runat="server" Width="100" Height="100" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.imgMat")%>'
CommandArgument='<%# DataBinder.Eval(Container, "DataItem.Matid")%>' ToolTip='<%# DataBinder.Eval(Container, "DataItem.ImgMat")%>'
CommandName="gallery" />
</li>
and on server side
protected void dl_IC(object source, DataListCommandEventArgs e)
{
try
{
if (e.CommandName.ToString() == "gallery")
{
but when the page is load I am not able to click the image, i.e. it is not in clickable mode while when I open the same page in Firefox or Chrome I can click the image and Item command event is also firing.
Additional Info
I am binding the datalist in > If(!ispostback) event
on Row Databound I am doing this
ImageButton imgM = (ImageButton)e.Item.FindControl("imgMat");
imgM .Attributes.Add("onload", "DoSomething('" + string value + "'," + 0 + ")");
Any help ?
Not positive if this is your problem or not, but you're server side method is "dl_IC" while the client side OnItemCommand is set to "dl_ic". Try making them match case and see if it's more reliable.
Related
Clicking on the anchor tag opens a menu and in one of the options(named Application) there is another menu where few applications are listed and I have to click on them. I am unable to click on it since it is not wrapped in a select tag.
here is the code:
<div class="menuBarSub mb_standardSub" menu="mn-1441711622465-/contextMenu" style="position: absolute; left: 1252.33px; top: 17px; display: block; z-index: 100;" role="navigation">
<table cellspacing="0" cellpadding="0">
<tbody role="menu" style="width: 100%;">
<tr id="/contextMenu/ID1277705525089001" class="menuItem" orientation="vertical">
<tr id="/contextMenu/ID1285350191126000" class="menuItem" orientation="vertical">
<tr id="/contextMenu/ID1412292365029000" class="menuItem" orientation="vertical">
<tr id="/contextMenu/ID1416325132235000" class="menuItem selected" orientation="vertical" aria-selected="true">
<tr id="/contextMenu/ID1332408920353004" class="menuItem" orientation="vertical">
</tbody>
</table>
</div>
Few points:
1. After clicking on the anchor tag you will have to wait for the presence of the menu. Use WebDriverWait and ExpectedConditions class for that.
2. You will have to hover over the menu appearing using Actions class clickAndHold(Locator).build().perform() method.
3. The get(0) is a different issue and just so that you should know it has nothing to do with selenium but has to do with Java. get(0) is method from List<E> collections Interface which is returned by WebDriver#findElements(Locator) API.
Let me know if you need further assistance.
Using asp.net 4.0. I have a page with a listview. I am trying to display a certain pre-defined Panel within the listview itemtemplate based on the current ItemBound value but not on the itemBound event....
For example, if the dataItem.Item("DataGapDesc") value is equal to "A", display Panel pnlPanelA, which will have 2 textboxes. If the dataItem.Item("DataGapDesc") value is equal to "B", display Panel pnlPanelB, which will have 3 textboxes and a checkbox, and so on.
Here's my current listview in the aspx:
<asp:ListView ID="EmployeesGroupedByDataField" runat="server" DataSourceID="sqlDataGapsForSelectedemployees" OnItemBound="employeesGroupedByDataField_ItemDataBound">
<LayoutTemplate>
<table id="Table1" runat="server" class="table1">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server" >
<tr id="Tr2" runat="server">
<th id="Th1" runat="server" style="text-align:left"><u>
employee</u></th>
<th id="Th2" runat="server" style="width:5%;text-align:center"><u>
# Items Missing</u></th>
<th id="Th3" runat="server"><u>
employee DOB</u></th>
<th id="Th4" runat="server"><u>
Primary Physican</u></th>
<th id="Th6" runat="server" style="width:10%;text-align:center;border-right: thin solid #000000"><u>
Missing Data Item</u></th>
<th id="Th5" runat="server" style="text-align: center;"><u>
Last Known Visit/Service</u></th>
<th id="Th7" runat="server" style="text-align: center;"><u>
Data Entry</u></th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr id="Tr3" runat="server">
<td id="Td2" runat="server" style="">
</td>
</tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<%# AddGroupingRowIfemployeeHasChanged()%>
<td style="text-align: right;border-right: thin solid #000000"><%# Eval("DataGapDesc")%> </td>
<td style="text-align: left;">
<%#Eval("ServiceDate")%>
 - 
<%# Eval("PlaceOfService")%>
</td>
<td>
<%# DisplaySpecificPanel()%>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Im calling the function DisplaySpecificPanel() and this is where I was "trying" to perform this behavior. That function in VB:
Public Function DisplaySpecificPanel() As String
Dim currentEmployeeNameValue As String = Trim(Eval("Employee").ToString().Substring(0, (Eval("Employee").ToString.Length) - 10).ToString())
If currentEmployeeNameValue = "DOE, JOHN" Then
'Panel1.Visible = True
Return String.Format("<asp:Button ID=""Button1"" runat=""server"" Text=""Button"" />")
Else
Return String.Format("<asp:TextBox ID=""TextBox1"" runat=""server""></asp:TextBox>")
End If
End Function
Right now, I'm just trying this functionality out by adding either a textbox or button based on the value but longer term, I wish to add the panels...
Well, my function is being called properly but the controls are not being placed on the rendered listview.
Any ideas? I'm I going about this correct? Many thanks...
Found this from another source. Makes sense but I wasn't completely versed in the lifecycle or behavior of the aspx page.
You will not be able to render server side controls using string
representation of the control. That approach works for plain HTML
controls. But, server side controls need to go through a rendering
mechanism which will not be invoked when you just set text property of
a control. Better alternative would be keeping just one panel in the
item template and adding controls dynamically in the itemdatabound
event based on conditions. Then, You can check if some condition is
true and then add textbox or a button accordingly. If there are too
many controls, you can also use UserControls. But, dynamic controls
will not be retained across page postbacks and you would need to add
them back with the same ID. If you do not want to handle all this
creation mechanism, you could just keep two independent panels and
update the visibility based on some conditions.
within Listview :
<td>
<asp:Panel runat="server" ID="pnlOne" Visible='<%# CanShowFirstPanel()%>'>
<asp:Button ID="Button1" runat="server" Text="Button" />
</asp:Panel>
<asp:Panel runat="server" ID="pnlTwo" Visible='<%# CanShowSecondPanel()%>'>
<asp:TextBox runat="server" ID="TextBox1" />
</asp:Panel>
</td>
Code-behind:
Public Function CanShowFirstPanel() As Boolean
'condition to check
Return True
End Function
Public Function CanShowSecondPanel() As Boolean
'condition to check
Return False
End Function
The CrystalReportViewer allows me to export my report to an Excel file, but it always saves the report as sheet "Sheet 1" in a new file.
Is there a way to get the CrystalReportViewer to save the report to an existing Excel file and specify what to name the sheet in saves the report to?
Thanks for the help.
Disable CrystalReportViewer export button
<CR:CrystalReportViewer .... HasExportButton="false" ... />
Add your export toolbar
<asp:Panel ID="exportPanel" ClientIDMode="Static" runat="server" CssClass="inLinePanel" >
<table style="height: 22px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px; margin-left: 1px; display: block; cursor: pointer; " id="CrystalReportViewer1_toptoolbar_addedButtons" class="" cellspacing="0" cellpadding="0" border="0" >
<tr>
<td title="PDF">
<asp:ImageButton ID="btnPdf" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/PDF.png" CssClass="AddedButton" />
</td>
<td title="word">
<asp:ImageButton ID="btnDoc" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/DOC.png" />
</td>
<td title="excel">
<asp:ImageButton ID="btnXls" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/XLS.png" />
</td>
<td title="excel no stile">
<asp:ImageButton ID="btnCsv" runat="server" OnClick="btnExport_Click" ImageUrl="~/Images/CSV.png" />
</td>
</tr>
</table>
</asp:Panel>
And this is the code-behind
protected void btnExport_Click(object sender, EventArgs e)
{
ReportDocument reportDocument = CrystalReportViewer1.ReportSource ;
// Stop buffering the response
Response.Buffer = false;
// Clear the response content and headers
Response.ClearContent();
Response.ClearHeaders();
try
{
string senderID = ((ImageButton)sender).ID;
if (senderID == "btnPdf")
reportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Page.Title);
else if (senderID == "btnXls")
reportDocument.ExportToHttpResponse(ExportFormatType.Excel, Response, true, Page.Title);
else if (senderID == "btnCsv")
reportDocument.ExportToHttpResponse(ExportFormatType.ExcelRecord, Response, true, Page.Title);
else if (senderID == "btnDoc")
reportDocument.ExportToHttpResponse(ExportFormatType.EditableRTF, Response, true, Page.Title);
// There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
}
catch (Exception ex)
{
Compliance.SmtpHelper.SendErrorMessage("Reportform.Aspx - QueryString: '" + clearQueryString + "' - Dettaglio errore: " + ex.ToString());
Response.Write(ex.StackTrace);
}
}
my code gota datalist with radio button and iv made it single selectable onitemdatabound....now im trying to evaluate a hiddenfield on basis of selected radio button
my code goes like this
aspx code
<asp:DataList ID="DataList1" runat="server" RepeatColumns = "4" CssClass="datalist1"
RepeatLayout = "Table" OnItemDataBound="SOMENAMEItemBound"
CellSpacing="20" onselectedindexchanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<br />
<table cellpadding = "5px" cellspacing = "0" class="dlTable">
<tr>
<td align="center">
<a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>'
Width = "100px" Height = "100px" style ="cursor:pointer" />
</td>
</tr>
<tr >
<td align="center">
<asp:RadioButton ID="rdb" runat="server" OnCheckedChanged="rdb_click" AutoPostBack="True" />
<asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
code behind
protected void SOMENAMEItemBound(object sender, DataListItemEventArgs e)
{
RadioButton rdb;
rdb = (RadioButton)e.Item.FindControl("rdb");
if (rdb != null)
rdb.Attributes.Add("onclick", "CheckOnes(this);");
}
protected void rdb_click(object sender, EventArgs e)
{
for (int i = 0; i < DataList1.Items.Count; i++)
{
RadioButton rdb;
rdb = (RadioButton)DataList1.Items[i].FindControl("rdb");
if (rdb != null)
{
if (rdb.Checked)
{
HiddenField hf = (HiddenField)DataList1.Items[i].FindControl("HiddenField1");
Response.Write(hf.Value);
}
}
}
}
the javascript im using...
function CheckOnes(spanChk){
var oItem = spanChk.children;
var theBox= (spanChk.type=="radio") ?
spanChk : spanChk.children.item[0];
xState=theBox.unchecked;
elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="radio" &&
elm[i].id!=theBox.id)
{
elm[i].checked=xState;
}
}
iam getting an error like this
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'pload Demonstration|'.
is there any other way to do this or can nyone plz help to get rid of this problem
The problem is probably your Response.Write() call. Take a look at this blog post. It outlines the reasons why this particular exception shows up, and how to prevent it. Also take a look at this StackOverflow thread.
Okey lets just remove response write...now i have following in my codebehind...rest is same
label5.text=hf.value.ToString();
now i am able to evaluate Label when i use update panel nd nested updatepanel like this
<asp:UpdatePanel ID="UpdatePanel9" runat="server" >
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatColumns = "4"
CssClass="datalist1" OnItemDataBound="SOMENAMEItemBound"
CellSpacing="10" onselectedindexchanged="DataList1_SelectedIndexChanged"
HorizontalAlign="Center" Width="500px">
<ItemTemplate>
<br />
<table cellpadding = "5px" cellspacing = "0" class="dlTable">
<tr>
<td align="center">
<a href="<%#Eval("FilePath")%>" target="_blank"><asp:Image ID="Image1" runat="server" CssClass="imu" ImageUrl = '<%# Eval("FilePath")%>'
Width = "100px" Height = "100px" style ="cursor:pointer" />
</td>
</tr>
<tr >
<td align="center">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="rdb" />
</Triggers>
<ContentTemplate>
<asp:RadioButton ID="rdb" runat="server" OnCheckedChanged="rdb_click" AutoPostBack="true" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:HiddenField ID="HiddenField1" runat="server" Value = '<%#Eval("ID")%>' />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
is there a way to to get this done without full page postback....asyncpostback trigger doesnt seem to work
I have a linkbutton that is nested in a datagrid that is nested in a datalist (yes, very strange, but unfortunately it's part of the site which I cannot change). Essentially I want the linkbutton to fire an event handler that calls Response.Redirect(e.CommandArgument)). In other words, I already have the URL that I want to redirect to, but I can't figure out how to get the event to trigger when I click on the linkbutton.
I have tried using the linkbutton OnClick events and the ItemCommand events for the datagrid but I dont think I am registering them correctly.
Here is the HTML for the controls.
<asp:DataList ID="dlstC" BorderWidth="0px" BorderStyle="None" CellPadding="2" CellSpacing="0"
runat="server">
<ItemTemplate>
<table cellpadding="0" cellspacing="0">
<tr style="padding-bottom: 4px">
<td style="height: 20px">
<asp:Label runat="server" ID="lblCertNum" Text='<%# "20" + (CStr(Container.DataItem("QuoteID").ToString) + "-" + CStr(Container.DataItem("QuoteRef").ToString)) %>'
Font-Bold="True" Font-Size="8pt"></asp:Label></td>
</tr>
<tr>
<td>
<asp:DataGrid ID="dgd_Certs" runat="server" ShowHeader="False" AutoGenerateColumns="False"
DataSource='<%# GetCert(CInt(Container.DataItem("QuoteRef"))) %>' BorderStyle="None"
BorderWidth="0" BorderColor="#ffffff" CellPadding="4" CellSpacing="0" OnItemCommand="DataGrid_EditItem">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="hlnCert" runat="server" Text='<%# Container.DataItem("CertName").ToString %>' CommandName="RedirectToCert"
CommandArgument='<%# BuildURLToCert(CInt(Container.DataItem("QuoteRef"))) %>' ToolTip="Click to view/edit certificate" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# "Created - " + CStr(Container.DataItem("DateCreated").ToString)%>'></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</td>
</tr>
</table>
</ItemTemplate>
And in the code behind I have
Public Sub DataGrid_EditItem(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs)
If e.CommandName = "RedirectToCert" Then
Response.Redirect(e.CommandArgument.ToString)
End If
End Sub
This is my latest attempt where I am trying to get the datagrids ItemCommand to fire when the client clicks on the link, but it's not working at the moment.
Failing this, is there an easier way to redirect the client to the correct page when they click on the linkbutton? I tried using the OnPostBackURL but the issue is that there are objects that need to be carried over that dont seem to be when I do this or when I just use a hyperlink with navigateurl set.
Thanks in advance for any help, this has had me stumped for 2 days straight.
I never managed to get the event handler to fire off of the linkbutton, but I did come up with a work around for the original problem, having variables passed from one page to another. I have used a hyperlink instead of a linkbutton, and used the query strings to pass reference numbers for the objects that I need to access on the new page.