Showing posts with label own. Show all posts
Showing posts with label own. Show all posts

Wednesday, March 28, 2012

Consuming a webservice from a custom control extender

I am making a first attempt at writing own extender using the toolkit, and I need to consume a web service. When I Google on Ajax and webservice, I get a lot of articles, but they all seem to involve modifying the ScriptManager tag to point to the web service I want, and you can't rely on that from an extender paradigm. I know the autocomplete control uses some sort of web service, but picking the code out is tough. Is there a plain vanilla, Hello World type of example of how to consume a web service from a custom control extender?

There seems to be a couple of ways to do this, check this post:

http://forums.asp.net/t/1163304.aspx

Although I like mine betterSmile

Hope this helps,

Elias.


Thanks Elias, that's what I was looking for.

Monday, March 26, 2012

Conflict between OnError and OnAsyncPostBackError events

I am updating my application from ATLAS to Ajax RC.

All my pages are inherited from my own WebPage subclass page that implements an OnError event and I have included the Script Manager with the OnAsyncPostBackError property in the master pages of the application.

When an exception is thrown within an Update Panel the Onerror event captures the exception and I haven't found a way to setup the AsyncPostBackErrorMessage. An alert message appears with the text:


Sys.WebForms.PageRequestManagerServerException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500


Any suggestions...?


Thanks...Antonio

Try to capture asynchronous?post?back error as the follow.
?????ScriptManager.AsyncPostBackError += new EventHandler<AsyncPostBackErrorEventArgs>(ScriptManager_AsyncPostBackError);
Determine if it is asynchronous post back:
?????ScriptManager.IsInAsyncPostBack;
Get synchronous post back error message:
?????ScriptManager.AsyncPostBackErrorMessage;
Get asynchronous post back source:
?????ScriptManager.AsyncPostBackSourceElementID;
Wish the above can help you.

I am having the same issue... We have existing sites that uses a standard basepage the overrides the OnError to catch any page errors. It will log the error and then redirect to a nicely formatted error page to explain the error. This works fine, but when I am inside a AJAX call and I get an error, I also get the following error

Sys.WebForms.PageRequestManagerServerException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

But if I remove my OnError Handler completely, then I will get the actual error in the javascript popup. How can I handle both the normal page errors and AJAX errors if just having the OnError seems to kill the AsyncPostBackError info?

Pat


changing UpdateMode from"Conditional" to "Always" solved my problem


I tried many ways to raise and catch the error with both OnError and OnAsyncPostBackError implemented. but no use. It always go to OnError handler.

Is someone suggests the complete code ... with master page, update panels on a page and onError and OnAsyncPostBackError events implemented?

Basically, I am looking to implement both handlers and distinguish to redirect Page request errors to OnError and Update panel requests errors to OnAsyncPostBackError;

Any help is appreciated in advance.


I found a way to do this ...

Put this snippet of code in your base Page codebehind ... this should capture every error that gets thrown.

1protected override void OnError(EventArgs e)2 {3 ScriptManager mgr = ScriptManager.GetCurrent(this);45 System.Exception ex =this.Server.GetLastError();67if (mgr.IsInAsyncPostBack)8 {9base.OnError(e);10 }11else12 {13this.Server.ClearError();1415base.OnError(e);1617 Response.Write(<html><head><title>Error</title></head><body>");18 Response.Write("<table class='Section'><tr class='SectionTitle'><td colspan='2'>Error Details</td></tr><tr><TD valign='top' class='FieldLabel' width='125px'>Error Message:</TD><td class='GenText'>");19 Response.Write(ex.Message);20 Response.Write("</TD></TR><TR><TD valign='top' class='FieldLabel'>Error Source:</TD><TD class='GenText'>");21 Response.Write(ex.Source);22 Response.Write("</TD></TR><TR><TD valign='top' class='FieldLabel'>Stack Trace:</TD><TD class='GenText'>");23 Response.Write(ex.StackTrace);24 Response.Write("</TD></TR><TR><TD colspan=\"2\"><a href=\"");25 Response.Write(Request.RawUrl);26 Response.Write("\">Return to previous page</a></td></tr></table></body></html>");27 Response.End();28 }29 }

Then in your master page (or whatever page) codebehind capture the AsyncPostBackError from the ScriptManager tag (making sure to hook the OnAsyncPostBackError in the aspx page to the ScriptManager1_AsyncPostBackError):

1protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)2 {3if (e.Exception.Data["ExtraInfo"] !=null)4 {5 ScriptManager1.AsyncPostBackErrorMessage =6 e.Exception.Message +7 e.Exception.Data["ExtraInfo"].ToString();8 }9else10 {11 ScriptManager1.AsyncPostBackErrorMessage ="The following error occurred: " + e.Exception.Message;13 }14 }


My updated code for handling OnError and OnAsyncPostBackError events ...

I took different approach like assigning event handlers early and then do accordingly. I have all my pages contain a Master Page and derived from Page Base ...MyAppPageBase

publicclassMyAppPageBase :Page
{
protectedoverridevoid OnInit(EventArgs e)
{
bool AttachPageErrorEventHandler =true;

// Determine if it is a page request, then only attach page error event handler
try
{
if (this.Page !=null &&
ScriptManager.GetCurrent(this.Page) !=null &&
ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
{
// Note: We are not attaching any event handler for page error -->
this.Page.Error -=newEventHandler(MyAppPage_Error);
this.Page.Error +=newEventHandler(MyAppPage_UP_Error);
AttachPageErrorEventHandler =false;
}
}
catch { }

if (AttachPageErrorEventHandler)
{
this.Page.Error +=newEventHandler(MyAppPage_Error);
this.Page.Error -=newEventHandler(MyAppPage_UP_Error);
}
base.OnInit(e);
}

protectedvoid MyAppPage_Error(object sender,EventArgs e)
{
Exception exBase = Server.GetLastError().GetBaseException();

if (exBase.GetType().Name =="HttpRequestValidationException")
{
>>> Redirect to a page to show that you are using <script> tag as data; Malformed data
}
else// all other / generic exception
{

this.Context.AddError(exBase);
Server.ClearError();
Server.Transfer("~/Error.aspx");
Response.Flush();/*The line is added to cancel the event bubbleup */
Response.End();/*The line is added to cancel the event bubbleup */
}
}

protectedvoid TPPage_UP_Error(object sender,EventArgs e)
{
Exception exBase = Server.GetLastError().GetBaseException();
if (exBase.GetType().Name =="HttpRequestValidationException")
{
string str ="You have submitted the data with <script>tag or with malformed data";
Response.Write(string.Format("{0}|error|500|{1}|", str.Length, str ));
}
else// all other types of exception
{
Response.Write(string.Format("{0}|error|500|{1}|", exBase.Message.Length, exBase.Message));
}
}
}

so far it is working great!

Wednesday, March 21, 2012

Component art tabstrip, change selected tab

I have an aspx page say Page1 that has 4 or 5 tabs in it. Each page is individually going to its own aspx page. So if I have 4 tabs, I have 4 more aspx page residing in the iframe tab of Page 1.
Now when I want to shift between tabs or aspx pages. Say on tab2, aspx page, I click a button and want to be able to go to tab3 and its aspx page.

I am able to show the contents of 3rd aspx page, but the tab strip till shows tab2.

How can I show that the selected tab is the third one.
I cant do TabStrip1.SelectedTab =

As TabStrip1 is in Page1. And I am browsing between the contents of tab2 and tabs 3 that are sitting in iframe tag of Page1

Please help me here
Thanks
-Sarah

I have same problem scenario to solve :(
I have same problem scenario to solve :(
I have same problem scenario to solve :(