Refreshing report inside dynamically created TabPanel - asp.net

I am having a ReportViewer inside the inner TabContainer TabPanel which i generated dynamically in Page Init event.
I load the report on OnActiveTabChanged event and I want to refresh the report on SelectedIndexChanged event.
How ever report doesn't change when I change the selected value of the DropDownList.
Note: I debug and the loadReport inside the SelectedIndexChanged execute properly.
Following is part of my code.
protected void DDL_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DDL = (DropDownList)sender;
ReportViewer rptViewer = (ReportViewer)DDL.Parent.FindControl("rptDateElectricity");
if (rptViewer == null)
{
rptViewer = new ReportViewer();
rptViewer.ID = "rpt" + "Date" + "Electricity"
rptViewer.Width = Unit.Pixel(1100);
loadReport(rptViewer, DDL, "Electricity", "Date");
DDL.Parent.Controls.Add(rptViewer);
}
}
protected void TCInner_OnActiveTabChanged(object sender, EventArgs e)
{
..............................
..............................
ReportViewer rptViewer = (ReportViewer)DDL.Parent.FindControl("rptDateElectricity");
if (rptViewer == null)
{
rptViewer = new ReportViewer();
rptViewer.ID = "rpt" + "Date" + "Electricity"
rptViewer.Width = Unit.Pixel(1100);
loadReport(rptViewer, DDL, "Electricity", "Date");
loadReport(rptViewer, DDL, monitoringObject, timePeriod);
}
}
}
I believe that this is a problem with view state.
I tried to set the EnableViewState false for the report viewer.
When i did i got the following runtime error:
"Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException: The Update
method can only be called on UpdatePanel with ID 'ReportArea' before
Render." Can anybody give a solution to this.
Thanks in advanced.

I got the same error when I told my report to autoRefresh, and it was caused by some javascript I'd inserted to override some of the ReportViewer's javascript (Microsoft.Reporting.WebFormsClient._ReportAreaAsyncLoad) to fix an error I'd been getting earlier. My custom javascript was triggering extra async load postbacks. I guess autorefresh conflicts with that.
Not sure if that's the cause of your problem though.

Related

Why would formview disappear in Edit Mode

I know I must be missing something simple but I cannot find it so I will pose the question here. I have a formview with two templates (item and edititem).
The form is bound to the itemtemplate in the page_Load event and works fine. However, if is use !IsPostBack in the code-behind, the formview disappears when the edit button is clicked. If I remove the postback check from page_load, then the form view appears after the edit button is clicked.
The page does have viewstate enabled.
In general, what steps are needed to get the formview to transition between modes correctly?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
source = Session["Source"].ToString();
acctType = Session["AccountType"].ToString();
acctNumber = Convert.ToInt32(Session["AccountNumber"]);
if (source == "LifeLineDS")
{
ObjectDataSource fvObjDS = new ObjectDataSource();
fvObjDS.TypeName = "LifelineDataAccess.LifelineSubscriber";
fvObjDS.SelectMethod = "GetLifelineDSSubscriber";
fvObjDS.SelectParameters.Add(new Parameter("AcctType", TypeCode.String, acctType));
fvObjDS.SelectParameters.Add(new Parameter("AcctNumber", TypeCode.String, Session["AccountNumber"].ToString()));
fvObjDS.DataBind();
if (fvObjDS != null)
{
fvSubscriber.DataSource = fvObjDS; //subscriber.ToString();
fvSubscriber.DataBind();
initialProgramValue = (fvSubscriber.FindControl("txtEligibility") as TextBox).Text;
}
}
// more code for other sources...
}
protected void btnEdit_Click(object sender, EventArgs e)
{
fvSubscriber.ChangeMode(FormViewMode.Edit);
fvSubscriber.DataSource = Session["subscriber"]; //Adding this line resolved !IsPostBack problem
fvSubscriber.DataBind();
ObjectDataSource programsObjDS = new ObjectDataSource();
programsObjDS.TypeName = "LifelineDataAccess.LifelineSubscriber";
programsObjDS.SelectMethod = "GetPrograms";
DropDownList ddlEligibility = ((DropDownList)(fvSubscriber.FindControl("ddlEligibility")));
if (ddlEligibility != null)
{
ddlEligibility.DataSource = programsObjDS;
ddlEligibility.DataTextField = "ProgramName";
ddlEligibility.DataValueField = "ProgramName";
ddlEligibility.SelectedValue = initialProgramValue; // Set selected value to subscribers current program
ddlEligibility.DataBind();
}
}
This
fvSubscriber.ChangeMode(FormViewMode.Edit);
fvSubscriber.DataBind();
seems to not to set the data source. The rule is that either you have the DataSourceID set in the declarative part of your code (*.aspx, *.ascx) and the binding is done automatically upon each postback OR you bind programmatically which involves setting the data source and calling the DataBind().
My recommendation would be to move your ObjectDataSource to the declarative part of the code and set the DataSourceID on the FormView to the ID of the ObjectDataSource. This is clean and easy and the binding works always.

radGrid control displays blank grid after date parameter is changed

I searched SO, google & Telerik forums, but could not find a solution.
I have an existing app (written by a previous developer) that is calling a stored procedure that populates a RadGrid control. It populates fine the first time around.
However, when I change the date parameter, click "search" button, I get a blank RadGrid control. When I click search the second time, the grid is populated. When I walk through the code, I get an error message
Column 'ID' does not belong to table Table.
How can I resolve the issue of having to click search twice to display data ?
My code behind is:
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
try
{
ViewState["newset"] = null;
CreateDatasource();
this.RadGrid1.DataBind();
this.RadGrid1.CurrentPageIndex = 0;
ViewState["newset"] = "new";
string idex = this.hdnindex.Value;
if (idex != string.Empty)
this.RadGrid1.MasterTableView.Items[int.Parse(idex)].Selected = true;
}
catch (Exception ex) {
this.lblMessage.Text = ex.Message;
}
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
try
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
HyperLink hLink = (HyperLink)item["ViewHyperLink"].Controls[0];
if (hLink != null)
hLink.Attributes.Add("onclick", "selectMe('" + item.ItemIndex + "');");
}
}
catch (Exception ex)
{
this.lblMessage.Text = ex.Message;
}
}
In the code behind above, when this.RadGrid1.DataBind() is called, the code steps into RadGrid1_ItemCreated loops through the if statement a few times, them goes into the if statement, comes out of the function, and then the catch statement of btnSubmit is called, which displays the error message "Column ID does not belong to table Table".
Any ideas on how to resolve this?
Maybe you should try Grid - Simple Data Binding. Also you this thread (RadGrid NeedDataSource Page load) on telerik forum talks in detail about Simple Data binding. I don't know if you are trying to use NeedDataSource, but I have had similar issues before and the Simple Data binding worked perfectly.
That sure sounds like to me you need to call RadGrid1.Rebind() somewhere. Try calling that for your last line in your try block inside btnSubmit_OnClick.
Also, what does this search button do? Does it filter the results based on a date?

ReportViewer.Find not working

I have a textbox, and a link button. On the same page I have a reportviewer.
The reportviewer is in updatepanel with linkbutton as async postback trigger.
I'm trying to find string (entered in textbox) in the report; when linkbutton is hit.
protected void lbtnFind_Click(object sender, EventArgs e)
{
ReportViewer1.Find(txtSearch.Text.Trim(), 1);
}
But that line gives error: Some parameters or credentials have not been specified Please help.
If txtSearch is a control you added, it will not be inside ReportViewer1.
If txtSearch is a control inside your ContentTemplate you should be searching in that control as follows:
var txtSrch = (TextBox)myUpdatePanel.ContentTemplate.Controls.FindControl("txtSearch");
You can get the text value from there and then set the parameters for the ReportViewer1 and refresh it.
ReportParameter[] parameters = new ReportParameter[1];
parameters[0] = new ReportParameter("Search", txtSrch.Text);
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.RefreshReport();

Using ASP.NET Cache/ViewState/Session

I'm trying to learn about Cache, Page ViewState, and Session. I created an ASP.NET web app in VS2010 and added 3 text boxes and a button to the page. I run in debug mode, enter random text into each, press the button, and nothing seems to be saved (all text is "null", as you'll see in the code). Am I performing these action in the wrong place? Do I need to add something to the web.config? Here is the code I'm using:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
if (Cache["textbox1"] != null)
TextBox1.Text = (string)Cache["textbox1"];
else
TextBox1.Text = "null";
if (ViewState["textbox2"] != null)
TextBox2.Text = (string)ViewState["textbox2"];
else
TextBox2.Text = "null";
if (Session["textbox3"] != null)
TextBox3.Text = (string)Session["textbox3"];
else
TextBox3.Text = "null";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Cache["textbox1"] = "(Cache) " + TextBox1.Text;
ViewState["textbox2"] = "(VS) " + TextBox2.Text;
Session["textbox3"] = "(Session) " + TextBox3.Text;
}
And the page header:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="State._Default" EnableSessionState="True" EnableViewState="True" %>
Thanks, and sorry for the rookie question. I'm very new to this.
Page_Load happens before Button1_Click. So on Page_Load you always replace textbox text with something from statebags ("null" at first and then "(Cache)" + "null" etc). What you enter in textboxes never lives until Button1_Click.
Use Page_PreRender instead.
Right now, every time you click the button, the code in your Page_Load procedure is overwriting the TextBox.Text values before the Button1_Click event gets a chance to save them.
If you change if (IsPostBack) to if (!IsPostBack), the values will only attempt to be loaded from session/viewstate/cache when you initially request the page. So you would have to request the page, set new values with the button, then re-request (Enter key in address bar) to run the code in Page_Load.
What I would suggest is you create a new button called "Load Values" whose Click event will run the code currently found in your Page_Load. That way you don't have to tie that code to whether the request was a postback or not. I think it would make your test results much easier to understand.

ASP.Net Gridview Update event

I have created a custom event to handle how the data should be updated in my gridview. The problem is, it is not firing. I have used debug mode and not even the breakpoint comes into effect when I click the update button.
Here is the event handler I have written:
protected void DocView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var rw = DocView.Rows[e.RowIndex] ;
var Doc = (TextBox)rw.FindControl("DocTB");
var Num = (TextBox)rw.FindControl("NumberTB");
var Iss = (TextBox)rw.FindControl("IssuedTB");
var Exp = (TextBox)rw.FindControl("ExpiryTB");
var Stat = (TextBox)rw.FindControl("StatusTB");
var con = new LinqDBDataContext();
var doc = (from i in con.Documents
where i.DocumentID == e.RowIndex
select i).Single();
doc.DocumentType = Doc.Text;
doc.Number = Num.Text;
doc.Issued = DateTime.Parse(Iss.Text);
doc.Expiry = DateTime.Parse(Exp.Text);
doc.Status = Stat.Text;
con.SubmitChanges();
DocView.EditIndex = -1;
}
The event just will not fire!
Sounds like your missing some plumbing!
Are you using some type of development kit such as Visual Studio?
Usually these kit's will do most of the plumbing for you. Be aware, there is a little more to wiring up the event handler than just providing the following function:
protected void DocView_RowUpdating(object sender, GridViewUpdateEventArgs e)
If your in Visual Studio, try clicking the lightning bolt on the GridView's property page to take a look at the event handlers for it.
Then double click the RowUpdating Event and try pasting your code in there to see if you can get your break point to fire!
Good luck.

Resources