Image URL not changing in Update panel - image

Ok this is probably really simple but I have been staring at it for too long now.
I have an AJAX AsyncFileUpload control that when a file is selected I want the Image next to it to change. I tried it in Javascript and it did nothing, i have since tried it server-side and still nothing. here is the client side.
<asp:UpdatePanel runat="server" ID="upnlConfidential">
<ContentTemplate>
<td>
<asp:AsyncFileUpload ID="_flupCV" runat="server" OnUploadedComplete="AdminFileUpload" />
</td>
<td>
<asp:Image ID="imgCV" runat="server" Height="25px" Width="25px" ImageUrl="~/Images/Exclamation.png"/>
</td>
</ContentTemplate>
</asp:UpdatePanel>
and here is the server side
protected void AdminFileUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
AjaxControlToolkit.AsyncFileUpload upload = (AjaxControlToolkit.AsyncFileUpload)sender;
if (upload.PostedFile != null)
{
switch (upload.ID)
{
case "_flupCV":
ImageCheckMark(imgCV);
break;
//etc...
}
}
}
private void ImageCheckMark(Image image)
{
image.Visible = true;
image.ImageUrl = "~/Images/CheckMark.png";
}
When the server side is called it sets the URL just fine but then nothing happens to the image, when I call the code again the URL is still the previous Exclamation image. its almost like its forgotten.
Can anybody help me on this please. Thanks in advance to all who contribute!

Use the OnClientUploadComplete event and jQuery :>

Related

Setting SelectedValue in a Telerik DropDownList in a RadGrid

I am trying to set the SelectedValue of a RadDropDownList in the EditTemplate of my RadGrid. The DataItemBound event appears to be throwing an error on compilation.
ASP.NET
<telerik:GridTemplateColumn DataField="givenAnswer" HeaderText="givenAnswer" UniqueName="givenAnswer">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "givenAnswer") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList ID="ddlGivenAnswer" runat="server" OnItemDataBound="ddlGivenAnswer_DataBound">
<Items>
<telerik:DropDownListItem Text="Yes" Value="Yes" />
<telerik:DropDownListItem Text="No" Value="No" />
</Items>
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>
C#
protected void ddlGivenAnswer_DataBound(object sender, GridItemEventArgs e)
{
if ((e.Item.IsInEditMode))
{
GridEditFormItem item = (GridEditFormItem)e.Item;
RadDropDownList ddl = (RadDropDownList)item.FindControl("ddlgivenAnswer");
ddl.SelectedValue = (string)DataBinder.Eval(e.Item.DataItem, "givenAnswer").ToString();
}
}
Error
CS0123: No overload for 'ddlGivenAnswer_DataBound' matches delegate 'DropDownListItemEventHandler'
This error is being throw on the telerik:RadDropDownList open tag line in ASP.NET. What am I missing here?
Main Edit:
Error CS0123:
First typing CS0123 in Google show me that you were using wrong parameter for your event. Probably a copypast fail. Delete the even in the aspx and ask to intelisense to create a new one. Or copypast this one.
protected void ddlGivenAnswer_ItemDataBound(object sender, Telerik.Web.UI.DropDownListItemEventArgs e)
ItemDataBound:
ItemDataBound occure when a data is bound in a control.
I'am pretty sure that inline declaration are not going to fire this event.
Minor Misconception:
Why would someone change the Value of a selected element dynamically?
It's like changing the value of a vote without changing the vote him self or the name on the vote.
What you want is to check the rigth item.
To check Waldo in the drop down list :
ddlGivenAnswer.FindItemByValue("Waldo").Selected = true;
To check the right Item:
ddlGivenAnswer.FindItemByValue(
DataBinder.Eval(e.Item.DataItem, "givenAnswer").ToString()
).Selected = true;

ZK MVC : how can i wait till the compose of another componant

i m working on a ZK project , using ZK MVC approach. what i did try to do is to initalize "a panel" after doAfterCompose a div , but the problem is that i got a "java.lang.NullPointerException"
and those are a simple exemple of what i did try to do . My view "mypage.zul"
<zk>
<borderlayout>
<west width="140px" splittable="true" collapsible="true" maxsize="140">
<div align="center" apply="dashboard.display">
<label value="WorkLoad"></label><checkbox></checkbox>
</div>
</west>
<center autoscroll="true" >
<div>
<portallayout id="portalLayout" maximizedMode="whole" width="100%" >
<portalchildren >
<panel id="panelworkload" >
<panelchildren>
<div width="100%" >
<charts id="workloadDay" type="column" />
</div>
</panelchildren>
</panel>
</portalchildren>
</portallayout>
</div>
</center>
</borderlayout>
</zk>
My conroler : "display"
public class display extends SelectorComposer<Div>{
#Wire
Checkbox objectif_checkbox;
#Wire
Panel panelworkload;
public void doAfterCompose(Div comp) throws Exception {
super.doAfterCompose(comp);
panelworkload.setTitle("hello workload");
}
}
and this is the exception that i got
java.lang.NullPointerException dashboard.display.doAfterCompose(display.java:24)
dashboard.display.doAfterCompose(display.java:1)
org.zkoss.zk.ui.impl.UiEngineImpl.doAfterCompose(UiEngineImpl.java:578)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:880)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:826)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:735)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:699)
what i have throught of it so far is that the div has been composed before the portallayout , that why the server cant reconize portallayout when div is created
can anyone help me pls ? i m kinda stuck here ...and thank you
The setTitle method for zk framework's Panel object is the following:
public void setTitle(String title) {
if (title == null)
title = "";
if (!Objects.equals(_title, title)) {
_title = title;
smartUpdate("title", _title);
}
}
There is nothing in there that would throw a NullPointerException. (And the stack trace would indicate it)
Therefore, the panelworkload should currently be null in the doAfterCompose(comp) object.
I would recommend you read through several of the answers on What is a NullPointerException, and how do I fix it? , although they do not do a great job of explaining how to diagnose a NullPointerException error, nor how to follow a stack trace.
Panel Source Reference

RadGrid Shows "No records to display" when there are records

I have a peculiar problem and I am not sure if anyone had come across this problem earlier. however the issue goes like this..
I have a grid with combination of TemplateColumns and BoundColumns and when I filter the grid using the filters under template columns I can see the results in UI (grid) but when I do the same in BoundColumns I do not see any results.. !!!
Funny thing is I can see the output from the query and its returns the correct number of results from DB. and its also assigned to the GridDataSource in the NeedDataSource event. however I cannot find the GridDataItem in the ItemDataBoundItem, I can fetch only headeritem, filteritem and footeritem.
It shows "No records to display" even when there are lot of records assigned to the DataSource.
Here I am attaching the screenshot, where you can see that the records count is displayed but not the records.. !!
Any help is highly appreciated.
here is the code sample
<ps:MassApprovalAjaxPanel runat="server" ID="m_UIRadAjaxPanel" LoadingPanelID="m_UIAsynBindLoadPanelInMasterPage">
<ps:MassApprovalRadGrid
runat="server"
ID="m_UIListingGrid"
SkinID="Grid_MassApproval"
OnNeedDataSource="ListingGrid_NeedDataSource"
OnItemDataBound="ListingGrid_ItemDataBound"
AllowFilteringByColumn="true"
EnableViewState="true">
<MasterTableView
DataKeyNames="CardID, WeekEnding, ClientPONumber"
ShowFooter="true">
<Columns>
<ps:NumericTextBoxTemplateColumn
UniqueName="CardID"
Width="70"
RelativeWidthRatio="90">
<ItemTemplate>
<asp:Label
runat="server"
Text='<%# string.Format("{0}/{1}", Eval(Constants.CARD_ID), Eval(Constants.VERSION)) %>' />
</ItemTemplate>
</ps:NumericTextBoxTemplateColumn>
<ps:TextBoxBoundColumn
UniqueName="ClientPONumber"
DataField="ClientPONumber"
Width="60"
RelativeWidthRatio="80" />
<telerik:GridClientSelectColumn UniqueName="SelectAll" HeaderText="All" />
</Columns>
</MasterTableView>
</ps:MassApprovalRadGrid>
</ps:MassApprovalAjaxPanel>
protected void ListingGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
m_UIListingGrid.DataSource = RadGridUtilUI.MassApprovalResultsGet();
}
protected void ListingGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
GridDataItem gridDataItem = e.Item as GridDataItem;
if (gridDataItem != null)
{
AddClientScripts(gridDataItem);
}
}
Thanks,
Preetham.
I found fix for this issue, it was quite simple and straight forward but we did not notice it.
protected void ListingGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
m_UIListingGrid.MasterTableView.FilterExpression = string.Empty;
m_UIListingGrid.DataSource = RadGridUtilUI.MassApprovalResultsGet();
}
Telerik has two types of filtering which is inbuilt filtering and user defined filtering that we do it through our SP's and Code. so we always have to set the filter value to null before doing our custom filtering.
Mark this as answer.
Thanks,
Preetham.

h:outputLink with f:ajax - method called, but link not shown

This does not work
<h:form style="display: inline;">
<h:outputLink value="#{title.link}" >
#{msg['g.readMore']}
<f:ajax event="click" immediate="true" listener="#{titlesBean.titleClicked(title.id)}" />
</h:outputLink>
</h:form>
What I want it to do is when clicked to call #{titlesBean.titleClicked(title.id)} and then go to the link. The method is called but it doesn't go to the link. There are several other ways to do it (with commandLink and then a redirect, but I would like to know why this is not working).
This is the method itself:
public String titleClicked(long titleId) {
this.titlesManager.addXtoRating(titleId, 1);
return null;
}
Note: this is only a sidenote, but I accidentally found out that this works:
<script type="text/javascript">
$('.share').popupWindow({centerBrowser:1,height:380,width:550});
</script>
<h:form style="display: inline;">
<h:outputLink styleClass="share" value="http://www.facebook.com/sharer.php...">
<img src="images/facebook-icon.jpg" />
<f:ajax event="click" immediate="true" listener="#{titlesBean.titleLiked(title.id)}" />
</h:outputLink>
</h:form>
Check out the styleClass="share"
Update: (I have less than 100 rep, so I cannot answer my own question for 8 hours, this is how to put it delicately - stupid).
I waited for a while, but nobody answered.
So this is my hacked solution ( I don't like it at all, but it works):
<h:form style="display: inline;">
<h:outputLink target="_blank" styleClass="click8" value="#{title.link}" >
#{title.heading}
<f:ajax event="click" immediate="true" listener="#{titlesBean.titleLiked(title.id)}" />
</h:outputLink>
</h:form>
And this is the important part:
<h:head>
<script type="text/javascript">
$(document).ready(function(){
$('.click8').click(function (event){
var url = $(this).attr("href");
window.open(url, "_blank");
event.preventDefault();
});
});
</script>
</h:head>
Note: this has to be in the header, otherwise I had a major bug with the link opening a thousand windows.
It does not work because there's means of a race condition here. Two HTTP requests are been sent simultaneously in the same window. One ajax to the server and one normal to the given link. The one which finishes sooner wins. You want to send the HTTP requests in sync. First the ajax one to the server and when it returns, then the normal one to the given link.
As to your hacky solution, it works because it uses JavaScript to open the URL in a new window instead of the current one and then blocks the link's default action, so the normal response just arrives in a completely separate window while the ajax response still arrives in the initial window. So there's no means of a race condition of two HTTP requests in the initial window anymore.
As to the final solution, this is not possible with standard set of JSF 2.0 components. Using <h:commandLink> and then doing a redirect is indeed doable, but the link is this way not crawlable by searchbots and it fires effectively a POST request, which is IMO more worse than your new window solution.
If you would really like to open the link in the current window, hereby keeping the target URL in the link's href, then I'd suggest to create a simple servlet which does the link tracking and redirecting job and let jQuery manipulate the link target during onclick.
Something like this
<a rel="ext" id="ext_#{title.id}" href="#{title.link}">read more</a>
(HTML element IDs may not start with a digit! Hence the ext_ prefix, you can of course change this whatever way you want.)
with
$(function() {
jQuery('a[rel=ext]').click(function(e) {
var link = jQuery(this);
var url = 'track'
+ '?id=' + encodeURIComponent(link.attr('id'))
+ '&url=' + encodeURIComponent(link.attr('href'));
if (link.attr('target') == '_blank') {
window.open(url);
} else {
window.location = url;
}
e.preventDefault();
});
});
and
#WebServlet(urlPatterns={"/track"})
public class TrackServlet extends HttpServlet {
#EJB
private TrackService trackService;
#Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String id = request.getParameter("id");
String url = request.getParameter("url");
if (id == null || url == null) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
trackService.track(id.replaceAll("\\D+", "")); // Strips non-digits.
response.sendRedirect(url);
}
}

Open a popup / new window from a gridview - VS2010, c#

Can anyone give me any hint on how I can open a new window by selecting a record from a gridview?
Im using response.redirect, and passing a value at present which opens the page fine but Id rather have a popup for this
thanks
You need to bind click event with the row of the grid view control
following code is just demo for you
following javascript open up the pop up window where you need to pass the url you want
<script>
function popWin(url){
window.open(url, '', '');");
}
</script>
follwing is samle code that attch the script with the gridview row to open up popup
code behind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow )
{
string url = "www.google.com";
e.Row.Attributes.Add("onclick","popWin('" + url + "')");
}
}
I had the same issue with response.redirect so went with a asp:HyperLink button instead. I loaded the URL by Binding it through the SQL Database. Here is the code:
<asp:TemplateField HeaderText="Google Map">
<ItemTemplate>
<asp:HyperLink runat="server" ID="hlGMap" Target="_blank" Text="Map" ImageUrl="~/gfx/google.png" NavigateUrl='<%# Bind("GoogleMapsURL") %>' />
</ItemTemplate>
</asp:TemplateField>
Hope it helps.

Resources