Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Wednesday, March 28, 2012

extending Gridview in Ajax

Hi,I'm binding a table to a gridview and it's all working fine. but what I would like to do is in one of the cells where the data bit big (a large paragraph) I would the cell to be able to show only the first few words than if the use move the mouse over the cell the whole paragraph will be displayed or the cell will expand or something.So, is there a way to extend the Gridview with Ajax allowing it to do that Or is there a control that I could be extended and add in a TemplateField that could do that!!!? Thanks

try this code on your rowbound event

protectedvoid GridView1_RowDataBound(object sender,GridViewRowEventArgs e)

{

if (e.Row.RowIndex != -1)

{

e.Row.Cells[4].ToolTip = e.Row.Cells[4].Text;

e.Row.Cells[4].Text = e.Row.Cells[4].Text.Substring(0, 15);

}

}

i wrap the text of column 4 th to only 15 character and showing the tooltip as a whole text which was the actual value of that column


You can integrate something like this into your grid:http://www.cssplay.co.uk/menu/more.html

-Damien


That's actually very nice thanks Mahadeo.


string strCount= e.Row.Cells[4].Text ;

if(strCount.Length > 16)

{

e.Row.Cells[4].Text = stringFormat("{0}{1}",strCount.SubString(0,15),"...")

}

extenders arent working at all

Hi. I have installed libarary and control toolkit, and I have the following code:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TaskCenter.WebForm1" EnableEventValidation="true" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI" TagPrefix="aj" %><%@dotnet.itags.org. Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI.Controls" TagPrefix="aj" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <aj:ScriptManager ID="sm" EnablePartialRendering="True" runat="Server" /> <asp:Label ID="test" runat="Server">test</asp:Label> <asp:Panel ID="panel1" runat="server" Enabled="true">testtttt</asp:Panel><ajax:DropDownExtender runat="server" ID="DDE" TargetControlID="test" DropDownControlID="panel1" OnResolveControlID="DDE_ResolveControlID" /> </div> </form></body></html>

Problem is, it doesn't work. The app builds without any problem, and when I open the page i see two text labels - test and testtt, no extender, no dropdown.

How do I fix it?

Look in the web.config for the SampleWebsite. Make sure you have the sections under httpHandlers and httpModules in your web.config.

Extender with inclusion of JS files in particular order.

Right now I'm working on an extender that needs to include numerous .js files I'd like to register for inclusion on a page.

I've added:

[assembly: System.Web.UI.

WebResource("first.js","text/javascript")]

[assembly: System.Web.UI.

WebResource("second.js","text/javascript")]

In the root of the Extender.cs class... as well as...

[ClientScriptResource("first","first.js")]

[

ClientScriptResource("second","second.js")]

Seems like if it were just one of the scripts by itslef it seems to do an ok job... but for scrips that rely on eachother, the straight up fail. Is the extender model only destined to have one script file period? If not, are scripts loaded and rendered in the order I add the ClientScriptResource attributes?

Is there another way I SHOULD be doing this? The .js files are being bundled in as Embedded Resource which is desired functionality, however the js variables that are now supposed to be present at the document scope simply arent. Somethign strange about which scripts are being loaded, or what order they are being loaded in.

Any advice would be greatly appreciated. Thanks

ClientScriptResource also takes named parameters, of which there is a LoadOrder and you can specify a load order. I found this to be the solution to my problem. Couple small little hurdles and I should be on my way.

Extender not working after partial page postback in Beta 2

Hi

I have a custom extender that worked fine under Beta 1 but has problems withUpdatePanels and partial page postbacks under Beta 2.

It appears that the behavior.js script resource associated with the extender is not send to the client after a partial page postback. The 'initialize' function on the behavior is not called after the partial page postback. The 'dispose' function is call the first time the partial page postback is execute so I would assume that the 'initialize' function should be called after the partial page postback has completed in order for the event handlers to be hooked up again.

The extender works perfectly when used outside of anUpdatePanel.

Any suggestions would be appreciated.

Cheers

I have the same problem with the collapseable panel. Did you find a solution?

I'm getting extremely annoyed, I've been searching and trying things for three days straight related to this. It seems that with Beta 2 your custom extender registers the $create() statement fine and is intialized properly within an update panel, but when you do a partial postback of this updatepanel the dispose method is never called, and the initialize is never recalled, so while you have the appropriate HTML Dom elements you no longer have anything hooked up to your client extender. I have seen SEVERAL posts about this in all the forums and not one response from microsoft. THis is the biggest issue keeping us from moving forward with our development. I at least want someone to acknowledge it's a problem. PLEASE MICROSOFT I'M BEGGING YOU TELL ME WHY MY CONTROLS WON'T DISPOSE FOR THE LOVE OF PETE.... okay I feel better now, but only slightly because my controls still don't work.

I also noticed this is a problem with any of the tookit extenders, I threw a watermark extender in anupdate panel and it works fine on the initial load, but fails to after a partial postback.


I have a sample app ready to go, very simple and it clearly identifies the problem, one page with an updatepanel a scriptmanager and a watermark extender and a button inside the update panel. When the page loads, the extenderhas the watermark text in it, when you hit the test button performing a partialpostback, no more watermark. Problem is I can't include it, anyone know how?


hello.

can you put it somewhere and send us the link?


I don't really have a public site I can put it to. I tried to attach it to the thread but it said I didn't have permission. Any ideas, if not send me a private reply and I'll send it to you if you have a place you can put it. Luckily it's a real simple website with only one page but it doe show the problem.

hello.

send it to my mail (get it from the profile) and refer the thread id on the mail message.


Thanks to Luis doing some work this weekend he figured out that in the simple example all that was needed was to change the enableeventvalidation to true and this caused the extender to work properly. However, now that I flip that in my main application I'm getting this error.

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@.Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the
data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

So the pain continues. Luis did make a point I agree with, whether or not EnableEventValidation="true" should not hinder these controls from working, specifically when to get the cascadingdropdown to work it needs to be set to false as I've seen in other posts. I'm opening a bug in codeplex this morning, but if anyone has been able to get their custom controls to work within an update panel please let me know. These bugs or incosistencies or whatever they are, are killing us. Everything was working great till this Beta release.


I've entered this as a bug

http://www.codeplex.com/WorkItem/View.aspx?ProjectName=AtlasControlToolkit&WorkItemId=5795


reading this post 2 days agou would have saved me 2 days of debugging (if only it would have been posted 2 days ago)


Anyway, I totally confirm this issue and I am voting it now on codeplex (http://www.codeplex.com/WorkItem/View.aspx?ProjectName=AtlasControlToolkit&WorkItemId=5795)


Thank god I no longer feel alone :) I've been trying everything for about 5 days straight now, our development has totally come to a crawl. I have a workaround in ming I am going to try this week, it'll be a temporary hack but I'll pst it when I'm done if it works.


zuke004:

Thank god I no longer feel alone :) I've been trying everything for about 5 days straight now, our development has totally come to a crawl. I have a workaround in ming I am going to try this week, it'll be a temporary hack but I'll pst it when I'm done if it works.

:)

You are not alone mate! My last 2 days were hell because of this issue. would you mind to share the temporary hack you had in mind?


And I am getting all my friends and colleagues that I've dragged with me into this issue trying to spot the problem to vote the bug you've logged on codeplex so that it gets prioritized

hello.

well, unfortunatelt, this seems to be an internal error which is very difficult to debug, i've found where the problem, but i still haven't understood why the code was written like that. the problem lies in the renderformcallback method of the pagerequestmanager class.

here's the code that is responsible:

if (this._owner.IPage.EnableEventValidation)
{
HtmlTextWriter writer2 = new HtmlTextWriter(TextWriter.Null);
foreach (Control control1 in containerControl.Controls)
{
control1.RenderControl(writer2);
}
}
rendering the control is necessary for the watermark extender to add the necessary scripts into the page (they'll ony be added if the render method of the scriptmanager control renders itself, ie, if its render method is called and this will only happen when EnableEventValidation is true as you can see from the previous code).

since this is a private auxiliary class used by scriptmanager, there's not much that can be done for now...


Hi Luis and thank you very much for your answer.

Could you recommend any partial/temporary solution that we could use for the moment (sorry for being lazy and asking such questions :)

Extender Controls not compiling

Hello ,

I recently started working with Ajax/Atlas. I have set up atlas extensions , and am trying to add the control toolkit . I follwoed the instructions , The items show up in the toolbox. When I drag any of the controls onto a webform . Intellisense tell me that the control is not a known element.

I realize this is vague, but if anyone can point me in the right. direction .

Thanks in advance

It seems to be related to how the controls are registered in the site . I have opened other sample projects where the controls are being used and they work fin, in that project .

Monday, March 26, 2012

Exposing Web Services from an ASPX page does not work

Hi All,

I am working with ATLAS technology. i am trying to imitatehttp://atlas.asp.net/quickstart/atlas/doc/services/default.aspx#webpage
"Exposing Web Services from an ASPX page"

i am having an aspx page which is inherited from our own Page class not from System.Web.UI.Page.

public partial class MainSearchPage : some namespace.MyPage

but this example does not work in this context.because in javascript, function OnWebRequestComplete1(result) returns null as result.

please help me in this issue.

thanks
Jaideep

hello.

well, i think that it should work. here's an example:

pypage.cs
namespace Test
{
public class MyPage:Page
{
[WebMethod]
public string HelloWorld(string s)
{
return "Hello '" + s + "'";
}
}
}

now, the aspx page:


Untitled Page

function handle()
{
PageMethods.HelloWorld( "Luis", handleComplete );
}

function handleComplete( res )
{
alert( res );
}

here everything is working properly...

Yes, this should work. To debug your issue, I would try:

Check on the server whether your method gets called at all.

yes, my server side code in code behind of aspx is not getting called.
in javascript side:

function handle()

{

PageMethods.HelloWorld("jaideep", handleComplete );

}

function handleComplete( res )

{

debug.dump(res,"Result",true);

alert( res );

}

in debugger, result is null.also my aspx is having one user control also.i tried to put debug in my code behind.but function HelloWorld is not getting called.

any clue as to what is happening.
thanks

jaideep


after viewing request/response in Fiddler ,i got a message indicating a corrupted viewstate.
same is the problem in following post:
http://forums.asp.net/1205269/ShowPost.aspx "ViewState and Atlas ".
and as per the instruction given , i removed "type =="hidden" condition from file
Atlas.js on line 3495.and now it is working!! but this approach is correct or not?
please let me know about this.
Thanks

JAideep


Copying my reply from the other thread:

I tried a few things, but was not able to repro. Could you give this a try with the March CTP to see if it still happens?

thanks,
David

exporting gridview to excel

hi

friends

i want to export gridview data to the excel in an ajax update panel

can any one of u please help regarding it it is working fine in normal website

it is not working in a ajaxenabledwebsite

What method are you using to export the data to excel? I recommend to use Aspose.Cells.


Hi,

I am afraid that this is normol.

You get the following error,don't you?

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

I think the error message explains the issue clearly.

You can set EnablePartialRendering=false for ScriptManager. then it works fine.

For more inormation, see:

Export GridView to Excel Complete Code!

Exporting gridview to excel and Ajax page get an error

Best Regards,


Hello.

you cannot integrate that technique easily on a page that has an updatepanel. anyways, i've written apost that exposes some ideas on how youmight get a solution for this kind of problem:

http://msmvps.com/blogs/luisabreu/archive/2007/10/17/asp-net-ajax-some-ideas-on-how-to-export-the-contents-of-a-gridview-to-an-excel-file-without-a-full-postback.aspx

Executing inline JavaScript on load

I have a rather complex ASP.NET control -WebDialog - that I'm trying to get working within Atlas' UpdatePanel.

The way the control currently works is by outputting JavaScript in its render method which is executed by the browser on load. The problem is that when an UpdatePanel is refreshed Atlas doesn't seem to execute inline scripts and so nothing happens.

I have tried moving outputting the JavaScript from the control's render method to its PreRender and then passing the script to RegisterClientScriptBlock, which Atlas does execute. While this method works great in simple scenarios, when the dialog has form controls like TextBox and Button it errors. Since I'm manually calling RenderControl on the nested content, and outside of the form's render, VerifyRenderingInServerForm throws an exception.

I don't want everyone who uses the control to have to use a custom page with VerifyRenderingInServerForm overridden.

Is there a solution that will update when an UpdatePanel refreshes yet works with forms controls and isn't obtrusive to the user developer?

hello.

i doubt it...i think that the only option is sending the javascript to the client though the clientscriptmanager class...


If I did that then I'd be dependant upon Atlas and have to include it's dll with my installer and output all it's JavaScript to the page which I don't want to do.
From what I'm reading, I believe that your JS code is registering with the window's onload event. The first time your page loads the window.onload event occurs, but subsequent partial postbacks don't cause the window.onload event to occur again.

Your thoughts of registering the script with RegisterClientScriptBlock (or RegisterClientStartupScript) seem to be on the right path. I'm not real sure from your posts why your having to manually call RenderControl (shouldn't the controls be added to the parent control's control collection?), but executing inline JS code on load is possible on an UpdatePanel refresh by registering with the ClientScriptManager.

- Joel

hello.

James Newton-King:

If I did that then I'd be dependant upon Atlas and have to include it's dll with my installer and output all it's JavaScript to the page which I don't want to do.

hum...i'm following you...you say that you don't want to be dependant upon atlas ( i think you're talking about the server side dll?)...but you also say that you have the control placed inside an updatepanel. the only way you'll use a panel is if you add the atlas dll to your app!

one more thing: if you're using asp.net (i assume you are) then you can use the clientscriptmanager without any problems since it was introduced in asp.net 2.0 to handle client script registration.


Luis Abreu:

hello.

James Newton-King:

If I did that then I'd be dependant upon Atlas and have to include it's dll with my installer and output all it's JavaScript to the page which I don't want to do.

hum...i'm following you...you say that you don't want to be dependant upon atlas ( i think you're talking about the server side dll?)...but you also say that you have the control placed inside an updatepanel. the only way you'll use a panel is if you add the atlas dll to your app!

one more thing: if you're using asp.net (i assume you are) then you can use the clientscriptmanager without any problems since it was introduced in asp.net 2.0 to handle client script registration.


Obviously if the dialog was inside an UpdatePanel then the app would be using Atlas but this control is also for regular ASP.NET 2.0 users. They're the reason I don't want to become dependant upon Atlas.

Sorry, I confused the ScriptManager in Atlas with the ClientScriptManager in ASP.NET 2.0. I am already using the ClientScriptManager (RegisterClientScriptBlock is a method on it) to register the script so I thought you must have meant the Atlas one. The problem I'm having using RegisterClientScriptBlock is that when I register the JavaScript and render the html in PreRender, ASP.NET throws an exception. It doesn't allow form form controls to be rendered outside of the form.

Anyway, I've come up with a solution that appears to work:
I'm rendering the HTML like you usually would on a page but inside a hidden div and outputting the other JavaScript using RegisterStartUpScript so that it works with Atlas's UpdatePanel. When the dialog is displayed I copy the HTML out from the hidden div into the dialog.

Execute UpdateProgress after page load

I have UpdatePanel, Grid and UpdateProgress controls, all working together using Ajax. When user does any action with the grid, Updateprogress shows nice animated gif "Loading adata...".

However, when the page loads, it takes 5 minutes to load data to the grid. There is no message, nothing, so the user may think he has Internet connection problems... How can I make Updateprogres to show the animated gif, when the page is initially loading data to the grid?

I was thinking maybe there is some event after the page loads, in this case I could load the data, after the page loads... Is it possible? What is the standard way to do it? Thanks

Hi rfurdzik,

When you want to have influence in the partial rendering of your page take a look at this:

http://ajax.asp.net/docs/overview/PageRequestManagerOverview.aspx

The PageRequestManager is the place to be to customize your partial rendering.

Regards,


In your case i would suggest to take a look at the: PageLoading event

"The pageLoading event is raised after the response from the server to an asynchronous postback is received but before any content on the page is updated. You can use this event to provide a custom transition effect for updated content."

Regards,


Hi I am not sure if that is what I need, I looked briefly at the link you gave me, but it seemsit points to PostBacks... I have no postback, this is the first time grid is loading. No user interaction occured yet, no postbacks. With postback works fine, just the initial load of data to the grid needs animation.

I am little bit lost in the info you gave me, would you guide me what event needs to be coded exactly and how to show the animation (I placed it in ProgressPanel)? Here is my scenario:

1) Page Loads

2) Animation shows "Loading data", grid is not visible yet

3) Data is loaded to the grid

4) Animation disappears

As I said earlier this is the initial load, first visit to the page, no postback yet...


There are two solutions:

The first you hide the gridview till the page completely loads and show only a progress image as shown below:

--------

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Sales Details</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div id="Progress"><img alt="Loading..." src="indicator.gif" /> Loading... </div>
<div id="GridContainer" style="display:none">
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString%>" SelectCommand="SELECT TOP (10000) SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount, LineTotal, rowguid, ModifiedDate FROM Sales.SalesOrderDetail"></asp:SqlDataSource>
</div>
</form>
<script type="text/javascript">
Sys.Application.add_init(function() {
$get("GridContainer").style.display = "";
$get("Progress").style.display = "none";
});
</script>
</body>
</html>

----------

The second solution is to induce a postback in load. In the sample below it is done by using a Timer control in the UpdatePanel. The GridView is not set to visible when the Page is not in PostBack and as soon as the timer starts a postback is done causing a partial page update which eventually causes UpdateProgress to be shown:

<%@. Page Language="C#" AutoEventWireup="true" %><script runat="server"> protected void Page_Load(object sender, EventArgs e) { GridView1.Visible = IsPostBack; Timer1.Enabled = !IsPostBack; }</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Sales Details</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdateProgress ID="Progress" runat="server"> <ProgressTemplate> <div> <img alt="Loading..." src="indicator.gif" />Loading...</div> </ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel ID="GridContainer" runat="server"> <ContentTemplate> <div id="Div1"> <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString%>" SelectCommand="SELECT TOP (10000) SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount, LineTotal, rowguid, ModifiedDate FROM Sales.SalesOrderDetail"> </asp:SqlDataSource> </div> <asp:Timer ID="Timer1" runat="server" Interval="100"> </asp:Timer> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> </form></body></html>


I think what youare reffering to is custom transition effect after postback. I have this functionality already done using Update panel and UpdateProgress controls. It all works.

What I need is to have the animation (under UpdateProgress) to be displayed during the INITIAL load of the page.

I was thinking maube no Ajax is needed in this case, maybe this can handled by standard ASP.NET code. Something like this (I am not sure what exactly events are):

1) Page load event - display animation (visble property = true), make grid invisible

2) Page loaded (?) - load data, (make grid visible, hide animation)

3) Postback - since I am changing the code now, not sure how the existing Ajax controls will behave (UpdatePanel + UpdateProgress...)


Hi rfurdzik,

Sorry that i didn't understand your question right. The option here above could give you a solution.

Regards,


yes, yes, your code makes sense. Thanks a lot!!! At least you understood what I need!

Dear Rama,

I like the second solution, it is very elegant. I do not fully understand the first one, but it is OK. I think your second solution needs to be modified in my case little bit. I am thinking to do this:

protected void Page_Load(object sender, EventArgs e)
{

if (IsPostback) {

LoadGridData();

}

GridView1.Visible = IsPostBack;

Timer1.Enabled = !IsPostBack;
}

As you see I have added additional if statement for loading the data to the grid, as showing the grid is not enough. Maybe that is why I was confused by the first example... Because I was thinking that even if youhide the grid,data load will occur, which will slow down my page load anyway... Maybe there is something I do not understand there...

However second solution seems will work for me...

Do you guys have some librarries with code? How do you find this? Do you organize your favorities in IE? That new IE is killing me, in version 7 it is so difficult to browse/bookmark anything if you have so many favorities. the reason is that it is all expended by deafault...


Oh, it is OK, your intention is the most important. You wanted to help! I may have not communicated well what I needed:) Thanks anyway for great info.

I have realized that the proposed second solution may also need to be changed more. This is the code I have in Page_Load:

if ((!Page.IsPostBack))

{

LoadData(15);

ViewState[

"CurrentTab"] ="0";// display the grid

}

As you can see I already check for Postback, I only load the data when it is first time load. This is of course for optimization purpose.

So now if I add timer code, we want the load of data to occur in THE FIRST POSTBACK ONLY. Not the first time the form is loading, but the first time postback is generated (by timer control). How would I acomplish this? I was thinking maybe setup a flag? I try this code, but it does not complie (I think some C# syntax issues, I am new to C#:))

m_DataLoaded = ((

Boolean)Session["m_DataLoaded"])=null ?true :false;

if ((Page.IsPostBack) & !(m_DataLoaded))

{

LoadData(15);

ViewState[

"CurrentTab"] ="0";

m_DataLoaded =

true;// display the grid

}

Session[

"m_DataLoaded"] = m_DataLoaded;

grdMyGrid.Visible = IsPostBack;

Timer1.Enabled = !IsPostBack;

What is wrong here? Something with casting I think... Please help.


Hirfurdzik ,

I used SqlDataSource control to bind to the grid which automatically binds the data provided the Grid is visible. So no penalty will be incurred.


Yes, I understand now. I can't figure this out what is wrong with my code, it compiles now, but getting error: m_DataLoaded = ((Boolean)Session["m_DataLoaded"])==null ? true : false; if ((Page.IsPostBack) & !(m_DataLoaded)) { LoadData(15); ViewState["CurrentTab"] = "0"; m_DataLoaded = true; // display the grid } Session["m_DataLoaded"] = m_DataLoaded; grdMyGrid.Visible = IsPostBack; Timer1.Enabled = !IsPostBack;This is the error:Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error: Line 96: m_dvInv = (DataView)(Session["m_dvInv"]);Line 97: Line 98: m_DataLoaded = ((Boolean)Session["m_DataLoaded"])==null ? true : false;Line 99: Line 100: if ((Page.IsPostBack) & !(m_DataLoaded))

Just changed editor back, beacuse the other one does not format. This one has some delay when typing, so many misstakes...

Yes, I understand now. I can't figure this out what is wrong with my code, it compiles now, but getting error:

m_DataLoaded = ((Boolean)Session["m_DataLoaded"])==null ? true : false;

if ((Page.IsPostBack) & !(m_DataLoaded))
{
LoadData(15);
ViewState["CurrentTab"] = "0";

m_DataLoaded = true;
// display the grid
}

Session["m_DataLoaded"] = m_DataLoaded;

grdMyGrid.Visible = IsPostBack;
Timer1.Enabled = !IsPostBack;


This is the error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 96: m_dvInv = (DataView)(Session["m_dvInv"]);
Line 97:
Line 98: m_DataLoaded = ((Boolean)Session["m_DataLoaded"])==null ? true : false;
Line 99:
Line 100: if ((Page.IsPostBack) & !(m_DataLoaded))



m_DataLoaded = ((Boolean)Session["m_DataLoaded"])==null ? true : false;

should be

m_DataLoaded = Session["m_DataLoaded"] ==null ? true : false


Thank you Rama Khrishna, it compiles fine and runs fine now. However the grid is not visible. So eighter the timer did not start, or something wrong with the logic. I will debug it now...

Saturday, March 24, 2012

Exception thrown from code inside an updatepanel is not handled by global.asax Application

Hi All

In the application I developed, I had the code to log the exceptions in Global.asax. This was working fine until I use Ajax update panel in the code behind of a few files.

When an exception happens in the code, called through update panel, Application_Error handler in the global.asax is never called.
Instead I can see an alert with the exception.message.

Is this a known issue? if so, is there a was to call the Application_Error automatically in case any exception thrown.

Thanks

Hi,

It's not a issue, but designed to work so.

If it's a asyncRequest, an custom error handler will be registered to handle any exception. The error message is encoded and returned in the internal error handler. And it's worth mentioning that this exception isn't swallowed and theoretically speaking, the appliction_error is able to fire.


Hi,

Thanks for the reply.

But the Application_Error event is not called.

I tried setting breakpoint in the function entry point and indused an Object Reference Is Nothing Errror within the code that is called through UpdatePanel. The breakpoint is not getting hit. Even in the test server, the errors are not getting logged. Is there any way, we can override the Ajax custom error handler or just make the Application_Error event to be called.


I used the following code, and it's able to trigger the Application_Error method.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); throw new Exception("custom exception"); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Can you try it? Please let me know the result.


Hi

One more thanks for the reply.

I tried the code, the exception is getting thrown, but still the breakpoint in application_error is not being hit.


Can you simplify your app into a single page along with web.config that is able to reproduce the problem and mail it to me?

Hi Mr.Raymond Wen,

Many thanks for your continued support.

Below I post a simple "Not in use" page, for your understanding

<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> </script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Partial-Page Update Error Handling Example</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox> / <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox> = <asp:Label ID="Label1" runat="server"></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
PartialClass _DefaultInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Try Throw New Exception("FOR TESTING")Finally End Try End SubEnd Class


GLOBAL.ASAX

'This code is not being called during an asyncronous postback'But this is called when a request is made directly without using UpdatePanel.Sub Application_Error(ByVal senderAs Object,ByVal eAs EventArgs)Dim exAs System.Exception = Server.GetLastError()TryIf ex IsNotNothing ThenWriteLog(ex)End IfServer.Transfer("~/ErrorDescriptionPage.aspx")CatchEnd TryEnd Sub

Hope this will help to identify the issue.

Thanks once again


One more thing is that I use Microsoft Entreprise Block for exception handling

Thanks


Still, I can fire the Application_Error method. I guess it's caused by come configurations. That's why I want your web.config file.

Can you post it here?

Exception has been thrown by the target of an invocation.

I have an Atlas enabled asp page working fine in Visual Web Developer 2005.

It has a Web Service with two methods one for an autocomplete and another to generate a datatable to populate a datagrid.

The second method makes calls two methods from a DataSet object.(one gets a row and the other its details.)

When I deploy to produccion the autocomplete works fine but populating the datagrid fails with:

Exception has been thrown by the target of an invocation

thrown by InternetExplorer.

I tested the Web Service calling its operations directly and it works fine.

Please help.

ps. the production machine has low space in C:\ drive.

In both cases I go against the same SQL Server 2000 database.

Since I posted the question above I was able to "deploy" to a Virtual Directory (called "LocalAtlas" situated on D:\VB Projects\VB Web Developer\Atlas Web Virtual Dir\ ) of my Local IIS and after I added the impersonation tag

<

identityimpersonate="true"userName="vvvvvvvv"password="pppppppp"/>

the page worked as expected. However, it is looking for the .asmx file in the same directory where Visual Studio looks.

But changing the KEY tag from

<

addkey="OBWebServiceRef.OBWebService"value="http://localhost:1459/AtlasWebSite1/OBWebService.asmx"/>

as created by Visual Web Dev to

<

addkey="OBWebServiceRef.OBWebService"value="http://localhost/LocalAtlas/OBWebService.asmx"/>

or anything else I can think of (in Web.config) does not work.

(I removed the fileAtlasWebSite1/OBWebService.asmxto avoid using it)

example codes

Hi,

is there anything out there that shows some working examples (codes) of the control toolkit? Nothttp://ajax.asp.net/ajaxtoolkit/, it only lists the properties but does not show how to use them.

Thanks.

Is it safe to assume that there is nothing like a turorial or a document that shows you how to create the controls? I googled for these but didn't find anything.

everything was fine, when suddenly AJAX Stopped working

I was working on a small AJAX application on a windows 2003 server web application running on IIS 6.0

I putted an AJAX timer control on the web form

and on the Tick Event I wanted a label called Label1 to take the current time every second

code:

Label1.Text = Now.ToString()

It was working , but somehow I was changing in the IIS configuration when the application stops working

I tried the same application on another PC (windows xp + Visual Studio 2005), it worked fine in debugging mode

so I installed Visual Studio 2005 on the server to know what's the problem, and in debugging mode, the application starts normally, but the label does not change its text value

I uninstalled AJAX Extensions, reinstalled again, nothing changed

I tried : aspnet_regiis -i

nothing changed, please help, I tried a lot, I think there is something about security scripts on the server that is not allowing AJAX scripts to work.

thanks in advance.

Hi,

Please make sure the virtual directory isconfigured as a Application and using the asp.net 2.0.

1. Run inetmgr command

2. Expand and navigate to the virtual directory

3. Right click it and select properties

4. Click Create Button in Application Settings section

5. Active ASP.NET tab

6. Make sure asp.net version is correct

Hope this helps.

Wednesday, March 21, 2012

Event to catch unavailable database with CascadingDropDown

I have the CascadingDropDown control working correctly with 2 DropDownLists. They're both being used with a database and I want to be able to catch any database errors (for example an unavailable db) before the DropDownLists display the dreaded [Method error 500]. From there I can hide the form panel and display a panel with a friendly error message. How would I go about doing that? With an ObjectDataSource I could catch it during the OnSelected event...

I haven't used the CascadingDropDown control but I assume it using the standard ASP.Net Ajax Library for async. calls. So se if the following way of handling exceptions in ASP.Net Ajax will work for you:

http://fredrik.nsquared2.com/viewpost.aspx?PostID=396&showfeedback=true

http://fredrik.nsquared2.com/viewpost.aspx?PostID=395&showfeedback=true

http://fredrik.nsquared2.com/viewpost.aspx?PostID=394&showfeedback=true


Fredrik

This doesn't seem to be working for me... I don't know if the CascadingDropDown behaves differently than the the UpdatePanel or if there's a problem with my configuration. I followed your examples and still receive the error as an item within the dropdown box on the page rather than an alertbox. I also attempted to change the innerHTML of a label using the PageRequestManager to no avail. Otherwise, very good articles that should come in handy with other AJAX controls.

Evaluate a returned object from Client-side callback

Ok...I'm a n00b to the Microsoft was of doing AJAX - I've been using Prototype.

I ran the tutorial video for the client callback, and had that working correctly.

Unfortunately, my real-world scenario is returning an object which from what I've been reading is neatly serialized by the Microsoft AJAX stuff into a JSON string/object/"thing".

This is where my brain explodes.

I don't know how to get the information out of this ethereal "thing" that's being returned by my web service. I can see the "stuff" when I look at it with Tamper Data, but don't know how to get at it.

Here's my client-side call:

function GetLicenseeDetails()
{
var retVal = eval(GetLicenseeInfo.LicenseeInfo(document.getElementById('<%= ddlLicensees.ClientID %>').value, OnComplete, OnTimeout, OnError));
alert(retVal);
return(true);
}

The alert I've thrown in there just reports 'undefined'.

If anybody's got a good place they can point me to learn what I'm doing wrong, I'd appreciate it very much. I'm hoping it's something simple...

Thanks in advance,

Ric

Hi

The calls are asynchronous which means that the reqyurn value is not immediately available to you. You will get the return object only in the OnComplete method.

function OnComplete(retVal) {

alert(retVal);

}

Errors in code view from AJAX scriptmanager control

When I am working on my page in code view, errors populate the error window ("ScriptManager" is not a known element... and a lot like that relating to any ajax control). But in design view everything works fine. It also is not using any of the ajax controls in the tag suggestion dropdown window. Any suggestions on how to fix this?

Hi

Did you include System.Web.Extension dll in your bin folder

Did you add

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<pages>
<controls>
<add tagPrefix="ajax" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>

in your web.config .

Try that out..

Hope that works it out

Bye