Showing posts with label object. Show all posts
Showing posts with label object. Show all posts

Wednesday, March 28, 2012

ExtenderControlProperty expression without quotes

How do I create an extender control property that will refer to a client function handler (or client object, or any client expression)?

If I create an extender propety as string (eg. string Property1), it will be rendered in client control creation as a quoted string:

$created(myComponent,{"Property1" : "value in quotes", ...

However I want it to be passed as client-side expression like that:

$create(myComponent,{"Property1": value without quotes, ...

I need something similar to ExtenderControlEvent attribute, which references a client-side handler, but it can only reference the ajax handler like MyFunction(EventArgs), and not any function with custom parameters, nor any custom client object).

In your client-side setter for the property, you can use: "this._expression = eval(value);".
I would suggest that, in your server-side setter, you make sure to check to make sure the developer doesn't try to use any parameters and to remove "()" from the value. If you don't, the above expression will execute the function and set this._expression to the return value of that function instead of setting this._expression to the function itself.

Hope that helps.

Monday, March 26, 2012

Export to Excel problem using UpdatePanels and Response object

This is how we are handling exporting to excel. I works fine when not surrounded by an Update Panel, but if I surround it with an Update Panel I get the ever so informing Unknown Error and in the output it throws an exception:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code

Here is My code that works not using the Update Panel

 
1#region ExcelImageButton_Click2protected void ExcelImageButton_Click(object sender, EventArgs e)3 {4// Serialize DataSource5 XmlDocument input =new XmlDocument();6 input = SerializeProductionVariance(dataSourceas IList);78 Response.Clear();9 Response.ContentType ="application/vnd.ms-excel";10 Response.Charset ="";11if (Selection.Count > 1)12 {13 Response.AddHeader("content-disposition","attachment; filename=MultiSelect.xls");14 }15else16 {17 Response.AddHeader("content-disposition","attachment; filename=Selection[0].Name +".xls");18 }1920 XsltArgumentList args =new XsltArgumentList();21 args.AddParam("date1","", ((DateTime)StartWebDateChooser.Value).ToShortDateString());22 args.AddParam("date2","", ((DateTime)EndWebDateChooser.Value).ToShortDateString());23 XslCompiledTransform xslt =new XslCompiledTransform();24 xslt.Load(Server.MapPath("~/Resources/Xsl/ExcelExportPM.xsl"));25 xslt.Transform(input, args, Response.OutputStream);26 Response.End();27 }28#endregion  
I get the error on the Response.End();
And only when I surrond the button in an UpdatePanel. But I need to surrond the whole user control this button is in. Any suggestions
 

Hi

Make sure that your export button is out side of the update panel.


And that's my problem. The usercontrol is surrounded by an UpdatePanel and has to be surrounded by said UpdatePanel.

hello.

tell me: when you click that button, do you only generate the excell file? if so, you can try a small workaround...instead of putting the code on a button click, put it in a custom handler. then, change the button so that it's a simple html button. this button then could try one of the following things:

1. open a new window which points to the handler

2. create an iframe and point it to the handler

Saturday, March 24, 2012

Exclude page_load during ajax content pannel update possible?

I have this in my behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(String.Format("{0:yyyy}", DateTime.Now).ToString()))
End Sub

The problem is, whenever I select a new value in my drop down list, it defaults itself back to the current month. Is there a way to exclude this from running when I am using an ajax update panel?

You can use Page.IsPostback for this. It is false for the very first request, and true for any postback (also true for async postback)

If you need to determine whether you have a full or an async postback, you can use:IsInAsyncPostBack


If anyone was curious as to how the syntax looked here it is. Worked like a charm. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If (Page.IsPostBack = False) Then DropDownList1.SelectedIndex = DropDownList1.Items.IndexOf(DropDownList1.Items.FindByText(String.Format("{0:yyyy}", DateTime.Now).ToString())) End If End Sub

Wednesday, March 21, 2012

Events

I would like to know if it is posible to obtain the data from theAtlas:datasource object via javascript.
When thedataAvailable event is raised, I'm able to capturre the event in javascript.
I see that it is sending two arguments with the event. I belive the first argument is the
sender and the second is an empty args value. Please correct me if this is wrong.

<!--
<div><spanid="RES">Some type of test data</span></div>


<atlas:DataSourcerunat="server"id="DataSource1"serviceUrl="~/DataService.asmx">
<dataAvailableHandler="traceDataAvailable1">
</dataAvailable>
</atlas:DataSource>

<scripttype="text/javascript">
function traceDataAvailable1()
{

var obj = arguments[0];
window.document.getElementById("RES").innerText = obj ;

}
</script>
-->

In your handler, "obj" will represent the datasource. So, to get to the data, you should do obj.get_data().
On a related note: you can rewrite traceDataAvailable1() to:
function traceDataAvailable(sender, eventArgs) {
...
}
Also, to display the data in the "res" span, you probably want toiterate over the contents of in the data object and concat it to the"innerHTML" property of the span.

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);

}

Error: top.document.documentElement is null or not an object

Hello,

I try to add Asp.net Ajax to a web site, but when I add a ScriptManager to a page
I get the error

Error: 'top.document.documentElement' is null or not an object

whenever I click on a control in that page
(e.g.?a TextBox)

Any ideas of what I might have missed?

Hello,

I have the same problem and I don't understand what is the error. I have the ScriptManager in the MasterPage file and the rest of the pages are working correctly.

Any idea?


Anyone figure this out? I'm having the same problem and it started right after upgrading to the release version. We have a page hosted inside of an iframe that throws the errors, so I'm wondering if it's related to that somehow?

Appreciate any help anyone has on this.


this page in the frame is one outside the immediate domain? Do a search on iframe for the last two weeks or so there was several posts on this ...there is also a fix link posted for it - i do not have the link handy but it is in previous posts...

For any other person who cannot find the elusive 'iframe' reference that has the miracle answer heres my solution. When I loaded the page it was being loaded in an iframe. Because the iframe is now the parent, it is also considered the top. Try using the parent function to reference the immediate parent. I.E. 'parent.document.documentelement'.

I hope that keeps the next person from wanting to beat people who leave references like "oh yeah I saw that here somewhere, it has something to do with..." as an answer to a question.


Im using scriptmanger in asp.net and using the update panel to hold the contents to avoid postback of the page in gridview . Im getting the error top.document.documentElement is null or not an object. Plzz helpme cause i want to know whre can i make changes in ajax or make any addn to avoid getting this error .


I've been having this same issue and I finally tracked it down. I have several other javascript files in my project, one in particular tracks the mouse position for a floating div. I have several top/module level variables, two in particular are top & left. They are the root of the problem and they interfer with the MicrosoftAjax.js file that is being served up by ScriptResource.axd.

Long story short, change your variable names from top and left, to something else like m_top, m_left (and don't forget to change it everywhere in your code). Variable naming just got a whole lot trickier now that we need to worry about outside scripts and not just our own.