Showing posts with label reference. Show all posts
Showing posts with label reference. Show all posts

Wednesday, March 28, 2012

Accessing objects in an UpdatePanel

I'm trying to reference a textbox that is located in an updatepanel and was successfully doing so until I installed the latest version of the CTP (Sept 2006) and now I don't have programmatic access to the objects in the update panel...how can I get to this? Below is my same code that worked in the last version:

<divid="footer">
<atlas:UpdatePanelID="udpStatusBar"runat="server"Mode="Always">
<ContentTemplate>
<asp:TextBoxID="tbxStatusMessage"runat="server"Enabled="False"SkinID="StatusBar"Width="455px"></asp:TextBox>
<asp:TextBoxID="tbxStats"runat="server"Enabled="False"SkinID="StatusBar"></asp:TextBox>
<asp:TextBoxID="tbxDate"runat="server"Enabled="False"SkinID="StatusBar"></asp:TextBox>
</ContentTemplate>
</atlas:UpdatePanel>
</div>

ASPX.cs

privatevoid DisplayMessage(string s)
{
((TextBox)this.Parent.Page.Master.Controls[3].FindControl("tbxStatusMessage")).Text = s;
}

myost2921:

I'm trying to reference a textbox that is located in an updatepanel and was successfully doing so until I installed the latest version of the CTP (Sept 2006) and now I don't have programmatic access to the objects in the update panel...how can I get to this? Below is my same code that worked in the last version:

<divid="footer">
<atlas:UpdatePanelID="udpStatusBar"runat="server"Mode="Always">
<ContentTemplate>
<asp:TextBoxID="tbxStatusMessage"runat="server"Enabled="False"SkinID="StatusBar"Width="455px"></asp:TextBox>
<asp:TextBoxID="tbxStats"runat="server"Enabled="False"SkinID="StatusBar"></asp:TextBox>
<asp:TextBoxID="tbxDate"runat="server"Enabled="False"SkinID="StatusBar"></asp:TextBox>
</ContentTemplate>
</atlas:UpdatePanel>
</div>

ASPX.cs

privatevoid DisplayMessage(string s)
{
((TextBox)this.Parent.Page.Master.Controls[3].FindControl("tbxStatusMessage")).Text = s;
}

You should be able to access the control directly. This should work for your DisplayMessage function:

tbxStatusMessage.Text = s;

The problem is that my DisplayMessage is sitting in a UserControl that is loaded dynamically into the page. The UserControl knows nothing of the page until runtime.
The problem is that the DisplayMessage method is found in a UserControl which is being dynamically added to the page at runtime. I'm having to use the FindControl command because of that reason. Any more ideas?

What error are you getting? Have you tried just calling page.findcontrol()?

A quick example:

.aspx file:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="wizard_validation.aspx.vb" Inherits="wizard_validation" %><%@. Register Assembly="AtlasControlToolkit" Namespace="AtlasControlToolkit" TagPrefix="act" %><!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> <atlas:ScriptManager runat="server" ID="blah2" EnablePartialRendering="true"></atlas:ScriptManager> <atlas:UpdatePanel runat="server" ID="blah" Mode="conditional"> <ContentTemplate> <asp:Wizard ID="NewFormWizard" runat="server" Width="100%" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" CancelButtonText="Cancel" DisplayCancelButton="true" > <WizardSteps> <asp:TemplatedWizardStep ID="WizardStepGeneral" runat="server" Title="*General"> <ContentTemplate> <h1>Header!</h1> </ContentTemplate> </asp:TemplatedWizardStep> </WizardSteps> </asp:Wizard> </ContentTemplate> </atlas:UpdatePanel> </div> </form></body></html>

Code-behind (in VB, but I'm sure you can figure it out):

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadDim iAs Integer Dim tmpwizardAs Wizard tmpwizard = Page.FindControl("NewFormWizard")If tmpwizardIs Nothing Then' failure i = 0Else' success i = 1End If End Sub

It returns with a success on that sample page. However, this is not a dynamically added control, so if you could post an example if using "Page.FindControl" doesn't work, it'd be easier to help ya out.


I figured out the problem...turns out it was actually simplified even more in this release and the cause of the error was something completely different. Thanks Matt!

Wednesday, March 21, 2012

A circular reference was detected while serializing an object of type "System.goblaization

Hi all,

I am trying to call a webservice through javascript to return a dataset to bind it to a datagrid on the client side.

I am using a scriptmanager and registered the service by setting the service path.

I am calling a method on a Textbox onKeydown event to call the webservice method. The web service is returning the a data set. But the problem is am geting an exception stating the following

The server method 'GetDataSet' failed with the following error: System.InvalidOperationException-- A Circular reference was detected while serializing an object of type "System.Globalization.CultureInfo"

Please help me out.

See the following code to get an idea about the problem i have

<WebMethod(EnableSession:=True)> _

PublicFunction GetDataSet(ByVal prefixTextAsString)As DataSet

Dim dtAs DataTable

dt =New DataTable

Dim drAs DataRow

dt =Me.GetSelectedTestSchema()

dr =Me.PopulateSelectedTestsRow("1020","dafda", dt)

Try

dt.Rows.Add(dr)

Catch exAs Exception

EndTry

Dim dsAs DataSet =New DataSet()

ds.Tables.Add(dt)

Return ds

EndFunction

Javascript code

function GenerateGrid()

{

var myGrid = igtbl_getGridById("grdSelectedTests");

TestListService.GetDataSet("x",OnWebRequestComplete);

// myGrid.Control.Set_DataDataSource(TestListService.GetDataSet("x").Table[0]);

//

}

function OnWebRequestComplete(results)

{

'I am using the Infragistics ultraWebgrid

var grdControl = igtbl_getGridById("grdSelectedTests");

grdControl.control.set_data(results);

}

Scriptmanager code

<asp:ScriptManagerID="ScriptManager1"runat="server">

<Services>

<asp:ServiceReferencePath="../AutoCompleteServices/TestListService.asmx"/>

</Services>

</asp:ScriptManager>

Hi,

According to my understanding to your problem, I don't think it's a AJAX specific issue. The exception is related to your server side code.

Can you debug your server side code to try to solve it?

Or you may post the code for methods:GetSelectedTestSchema() andPopulateSelectedTestsRow here.


We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.


I too am having the same problems.

I'm using C# to write my webservice, I have almost an identical setup for the client-side scripts.


I get this error even when returning an empty DataSet.


 [WebMethod]public DataSet GetData() {return new DataSet(); }

Does anyone know what this error message is telling me? I tried debugging it, and no exception is thrown from the webservice and it works fine when I send a soap request to it.

Thanks,

Lee


You may try to overcome it by setting response format to XML. For instance:

[System.Web.Script.Services.ScriptMethod(ResponseFormat=System.Web.Script.Services.ResponseFormat.Xml)]
public DataSet GetData()
{

A Circular Reference Was Detected error

Hi there,

This has been confusing me to no ends for the past weekend and I ask for your help. When I try to access an IList of Type <SampleRow> or any list structure for that matter, I get this:

A circular reference was detected while serializing an object of type ...<- Many types have popped up (System.Reflection.Module) for example.

I've been trying to run the samples in the documentation with no more success (same error). I'm thinking this has to do with some libraries loaded and not the code itself. I have looked in the GAC, uninstalled/reinstalled everything from VS2005 to the ATLAS Framework (even IIS) with no go. I need to get the list structure for the listview control of ATLAS. It this can help, I'm pasting the stacktrace. Also, I'm not sure this is a specific ATLAS error but I can't tell otherwise. Thanks for your help. If you need anything more, please ask.Smile

[InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.Module'.]
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +766
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeCustomObject(Object o) +706
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +908
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeCustomObject(Object o) +706
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +908
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeCustomObject(Object o) +706
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +908
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeCustomObject(Object o) +706
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +908
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeEnumerable(IEnumerable enumerable) +159
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +874
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeCustomObject(Object o) +706
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValueInternal(Object o) +908
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.SerializeValue(Object o) +90
Microsoft.Web.Script.Serialization.JavaScriptObjectSerializer.Serialize(Object o, IJavaScriptSerializationContext context) +62
Microsoft.Web.UI.Controls.InitialData.GetDataServiceResult() +589
Microsoft.Web.UI.Controls.InitialData.RenderScript(ScriptTextWriter writer) +248
Microsoft.Web.UI.Controls.InitialData.Microsoft.Web.Script.IScriptObject.RenderScript(ScriptTextWriter writer) +31
Microsoft.Web.UI.ScriptManager.RenderXmlScript(TextWriter writer) +735
Microsoft.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +663
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +96
System.Web.UI.Page.PerformPreRenderComplete() +32
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +479

Lesson learned: commenting the web.config file temporarily and forgetting about it is a bad idea. I had the converters section commented out, re-enabling them solved the problem. If it can help anyone to learn from my mistake then I won't have posted in vain!

Thanks.