Click here to Skip to main content
15,890,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am having this error "Web Service Call Failed: 500".

I am using an AJAX PopupControlExtender which would show a popup once mouseover on an image in row of a grid view occurs.

Now, when mouseover occurs, i receive this error.

Please help me as i am really stuck!

Thanks

CODE:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
using Sales_DAL;
using Sales_BOL;
using AjaxControlToolkit;

using System.Text;
using System.Web.Services.Description;
public partial class MCTX_Internal_SuperAdmin_frmShowDailyOutput : System.Web.UI.Page
{
    Dlayer dl = new Dlayer();
    _DailyOutput objDO = new _DailyOutput();
    _ShowDailyOutput bl = new _ShowDailyOutput();
    DataTable dt_Grid = new DataTable();
    string userid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetEmpName();
            DataTable dtUserID = new DataTable();
            dtUserID = bl.selectuserid();
            ddlEmployees.DataSource = dtUserID;
            ddlEmployees.DataTextField = "user_id";
            ddlEmployees.DataBind();
            ddlEmployees.Items.Insert(0, "---Select---");
        }
    }
    public void GetEmpName()
    {
        string str = Session["Username"].ToString();
        DataTable dt_Name = objDO.fnGetEmpName(str);
        lblEmpName.Text = dt_Name.Rows[0]["E_Name"].ToString();
        lblEmpName.ForeColor = System.Drawing.Color.Magenta;
    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
        if (FromDate.SelectedValue == null || ToDate.SelectedValue == null)
        {
            lblError.Text = "Please Select From/To Dates";
            lblError.ForeColor = System.Drawing.Color.Red;
            gvShowDailyOutput.Visible = false;
        }
        else if (ddlEmployees.SelectedItem.Text == "  ---Select---  ")
        {
            lblError.Text = "Please Select Employee";
            lblError.ForeColor = System.Drawing.Color.Red;
            gvShowDailyOutput.Visible = false;
        }
        else
        {
            DataTable dttest = new DataTable();
            dttest = Results();
            if (dt_Grid.Rows.Count > 0)
            {
                if (!IsPostBack)
                {
                }
                gvShowDailyOutput.DataSource = dt_Grid;
                gvShowDailyOutput.DataBind();
                lblError.Text = string.Empty;
                gvShowDailyOutput.Visible = true;
            }
            else
            {
                gvShowDailyOutput.Visible = false;
                lblError.Text = "No Record Found";
                lblError.ForeColor = System.Drawing.Color.Red;
            }
        }
    }
    public DataTable Results()
    {
        DateTime FrmDate = new DateTime();
        FrmDate = FromDate.SelectedDate;
        DateTime TDate = new DateTime();
        TDate = ToDate.SelectedDate;
        userid = ddlEmployees.SelectedItem.Text;
        dt_Grid = bl.selectGridData(userid, FrmDate, TDate);
        return dt_Grid;
    }
    protected void gvShowDailyOutput_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvShowDailyOutput.PageIndex = e.NewPageIndex;
        Results();
        gvShowDailyOutput.DataSource = dt_Grid;
        gvShowDailyOutput.DataBind();
    }
    protected void gvShowDailyOutput_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            PopupControlExtender pce = e.Row.FindControl("PopupControlExtender1") as PopupControlExtender;
            string behaviorID = "pce_" + e.Row.RowIndex;
            pce.BehaviorID = behaviorID;
            Image img = (Image)e.Row.FindControl("Image1");
            string OnMouseOverScript = string.Format("$find('{0}').showPopup();", behaviorID);
            string OnMouseOutScript = string.Format("$find('{0}').hidePopup();", behaviorID);
            img.Attributes.Add("onmouseover", OnMouseOverScript);
            img.Attributes.Add("onmouseout", OnMouseOutScript);
        }
    }
    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    public static string GetDynamicContent(string DynamicContextKey)
    {
        DropDownList ddlEmployees = new DropDownList();
        StringBuilder b = new StringBuilder();
        DataTable table = new DataTable();
        _ShowDailyOutput sdo = new _ShowDailyOutput();
        table = sdo.selectPopupData(ddlEmployees.SelectedItem.Text, DynamicContextKey);
        b.Append("<table style='background-color:#f3f3f3; border: #336699 3px solid; ");
        b.Append("width:350px; font-size:10pt; font-family:Verdana;' cellspacing='0' cellpadding='3'>");
        b.Append("<tr><td colspan='3' style='background-color:#336699; color:white;'>");
        b.Append("<b>Report Details</b>"); b.Append("</td></tr>");
        b.Append("<tr><td style='width:80px;'><b>Hour No</b></td>");
        b.Append("<tr><td style='width:80px;'><b>From Time</b></td>");
        b.Append("<tr><td style='width:80px;'><b>To Time</b></td>");
        b.Append("<tr><td style='width:80px;'><b>Report Time</b></td>");
        b.Append("<tr><td style='width:80px;'><b>Activity</b></td>");
        b.Append("<tr>");
        b.Append("<td>$" + table.Rows[0]["hourNo"].ToString() + "</td>");
        b.Append("<td>" + table.Rows[0]["fromTime"].ToString() + "</td>");
        b.Append("<td>" + table.Rows[0]["rptTime"].ToString() + "</td>");
        b.Append("<td>" + table.Rows[0]["TaskDetails"].ToString() + "</td>");
        b.Append("</tr>");
        b.Append("</table>");
        return b.ToString();
    }

}
public class _ShowDailyOutput
{
    Dlayer dl = new Dlayer();
    string query;
    public DataTable selectuserid()
    {
        DataTable dt = new DataTable();
        query = "select user_id from user1";
        dt = dl.DA_getTable(query);
        return dt;
    }
    public DataTable selectGridData(string UserID, DateTime FrmDate, DateTime TDate)
    {
        DataTable dt = new DataTable();
        query = "select CONVERT(varchar(20),currentdate,101) AS CurrentDate ,DailyReport.DailyReport_ID, DailyReport.MyOutput from DailyReport INNER JOIN ReportDetails on ReportDetails.DailyReport_ID = DailyReport.DailyReport_ID where user_id = '" + UserID + "' and CurrentDate between '" + FrmDate + "' and '" + TDate + "'";
        dt = dl.DA_getTable(query);
        return dt;
    }
    public DataTable selectPopupData(string ReportID, string ContextKey)
    {
        string query;
        Dlayer dl = new Dlayer();
        DataTable dt = new DataTable();
        query = "select ReportDetails.hourNo, ReportDetails.fromtime, ReportDetails.toTime, ReportDetails.rptTime, ReportDetails.TaskDetails from ReportDetails Inner Join DailyReport on ReportDetails.DailyReport_ID = DailyReport.DailyReport_ID where DailyReport.DailyReport_ID = '" + ReportID + "' and user_id = '" + ContextKey + "'";
        dt = dl.DA_getTable(query);
        return dt;
    }
}
Posted
Updated 4-Jul-11 23:17pm
v2
Comments
Prerak Patel 5-Jul-11 5:12am    
Share some relevant code.
Ahsan Mirza 5-Jul-11 5:18am    
I have attached my code, now please help me!

1 solution

A status 500 error indicates that there was a server error. My suspicion is that the problem lies on this line:
C#
table = sdo.selectPopupData(ddlEmployees.SelectedItem.Text, DynamicContextKey);
This is running inside an AJAX call, so the page lifecycle is circumvented which means that ddlEmployees.SelectedItem.Text has no relevance. Try passing this value in to your method instead, and using that (you'll have to populate the parameter from the JavaScript).
 
Share this answer
 
Comments
Ahsan Mirza 5-Jul-11 5:26am    
Can you show me how!
Pete O'Hanlon 5-Jul-11 6:20am    
I can't see your JavaScript to tell you what to put in before the call to GetDynamicContent, but you could use the following code to get the value that you need to pass in as the selected value from the drop down list: selectedValue = $('select.myControlId option:selected').val();

You'd pass the result from selectedValue in as the other parameter, and you need to replace myControlId with the ClientID of ddlEmployees to get the proper ID of the control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900