Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Saturday, March 24, 2012

Strange Error when executing a function

in my code-behind i call a class method that returns a string value...
i run step by step and works great!!

but when i run without breakpoint... sometimes i get error because my string is empty...
and then i run again step by step... and the surprise! works fine again...

why is this happening??

this is my code-behind

string param = " ";

param +=ConfigurarLoja.RetParams( );

Session.Add("ssnHabItemVincPromo",param);

if(param == " ")

{

response.redirect("~/Erro.aspx");

}

And this is my class method:

publicstaticstring RetParams()

{

string param ="";

int cd_empresa =Convert.ToInt32(HttpContext.Current.Session["ssnCdEmpresa"]);

string sql ="SELECT TOP 1 * FROM LjConfig WHERE cd_empresa = " + cd_empresa +" AND ISNULL(DATEADD(dd, 01, dt_exclusao), GETDATE()) > GETDATE() ORDER BY dt_inclusao DESC";SqlConnection con =newSqlConnection(ConfigurationManager.ConnectionStrings["StringDeConexao"].ConnectionString);

con.Open();

SqlCommand cmd =newSqlCommand(sql, con);

SqlDataReader dr = cmd.ExecuteReader();

dr.Read();

if (dr.HasRows)

{

param ="-" + dr["cd_empresa"].ToString().Trim();

}

con.Close();

return param;

}

ops... it seems solved...
i change the sql command 'WHERE'... i think it was a problem with the GETDATE... now its working fine...

AND (ISNULL(DATEADD(dd, 01, dt_exclusao), DATEADD(dd, 01, GETDATE())) > GETDATE()) "

Thursday, March 22, 2012

strange inconsistency referencing controls in Formview itemtemplate

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?

Here is the code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub

Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub

The line of code where the error occurs is cancelButton1.Text = "Done"

Thanks in advance.

-- NedFollowup: In researching this I came across a comment that only the
controls in the current mode are accessible; if the formview is in edit
mode then only the controls in the <edititemtemplateare accessible,
if in read-only mode then only the controls in the <itemtemplateare
accessible. This might explain this except that an update is supposed
to automatically return the formview to read-only mode, right? Or does
that happen later (after the formview_itemupdated() has terminated)?
So I tried explicitly changing the mode to read-only within the
itemupdated subroutine, but I still get the same error.

Hope someone can relieve my frustration.

-- Ned

Ned Balzer wrote:

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?
>
Here is the code:
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub
>
Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub
>
>
>
The line of code where the error occurs is cancelButton1.Text = "Done"
>
Thanks in advance.
>
-- Ned


1) Why not just use the control's variable? If the control has an id of
btnCancel1 and it's marked runat="server", then just do btnCancel1.Text =
"Done"

2) Are you using master pages? Control ID's change when placed into a
content placeholder on a master page. Use the DevToolBar to explore the DOM
and determine what your control's ID actually is on the client size.

"Ned Balzer" wrote:

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?
>
Here is the code:
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub
>
Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub
>
>
>
The line of code where the error occurs is cancelButton1.Text = "Done"
>
Thanks in advance.
>
-- Ned
>
>


1) When I try that, I get an error in Visual Web Developer 2005: "Name
'btnCancel1' is not declared." It is marked runat="server" but I think
the problem arises because it is buried within the formview, so it's
not a normal button control.

2) No, I am not currently using master pages.

-- Ned

William Sullivan wrote:

Quote:

Originally Posted by

1) Why not just use the control's variable? If the control has an id of
btnCancel1 and it's marked runat="server", then just do btnCancel1.Text =
"Done"
>
2) Are you using master pages? Control ID's change when placed into a
content placeholder on a master page. Use the DevToolBar to explore the DOM
and determine what your control's ID actually is on the client size.
>
"Ned Balzer" wrote:
>

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?

Here is the code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub

Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub

The line of code where the error occurs is cancelButton1.Text = "Done"

Thanks in advance.

-- Ned


Well, it doesn't make sense to me, but I found the suggestion somewhere
and tried it: calling bookformview.databind() before attempting to
reference the object, and the error went away. Problem is, the button
text is not being changed either.

Hmmmmmm

Ned Balzer wrote:

Quote:

Originally Posted by

1) When I try that, I get an error in Visual Web Developer 2005: "Name
'btnCancel1' is not declared." It is marked runat="server" but I think
the problem arises because it is buried within the formview, so it's
not a normal button control.
>
2) No, I am not currently using master pages.
>
-- Ned
>
William Sullivan wrote:

Quote:

Originally Posted by

1) Why not just use the control's variable? If the control has an id of
btnCancel1 and it's marked runat="server", then just do btnCancel1.Text =
"Done"

2) Are you using master pages? Control ID's change when placed into a
content placeholder on a master page. Use the DevToolBar to explore the DOM
and determine what your control's ID actually is on the client size.

"Ned Balzer" wrote:

Quote:

Originally Posted by

Can anyone explain why in the following code, where btnCancel1 is a
Button inside the itemTemplate of the formview, the first call to
change the text of the button, in the Page_Load sub, works fine, but
the second call, in the bookFormView_ItemUpdated sub, throws an
exception (Object reference not set to an instance of an object)? And
if you know why, can you suggest a workaround?
>
Here is the code:
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not Page.IsPostBack Then
bookFormView.ChangeMode(FormViewMode.ReadOnly)
Dim cancelButton As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton.Text = "Cancel"
End If
End Sub
>
Protected Sub bookFormView_ItemUpdated(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.FormViewUpdatedEventArgs ) Handles
bookFormView.ItemUpdated
Dim cancelButton1 As Button =
CType(bookFormView.FindControl("btnCancel1"), Button)
cancelButton1.Text = "Done"
End Sub
>
>
>
The line of code where the error occurs is cancelButton1.Text = "Done"
>
Thanks in advance.
>
-- Ned
>
>

Strange parse error calling ASP.Net WebService

By making a call to a webservice I receive the following error page, we did a
complete new build but the error still exist:

The installation of the webservice is on an win 2003 standard service pack 1
server.

Server Error in '/BackupAgentServices' Application.

------------------------

Parser Error

Description: An error occurred during the parsing of a resource required to
service this request. Please review the following specific parse error
details and modify your source file appropriately.

Parser Error Message: The check of the module's hash failed for file
'System.EnterpriseServices.Thunk.dll'.

Source Error:

Line 1: <%@dotnet.itags.org. Application Codebehind="Global.asax.cs"
Inherits="BAWebService2.Global" %>

Source File: C:\Program Files\BackupAgent Server
2006\BackupAgentServices\global.asax Line: 1

------------------------

Version Information: Microsoft .NET Framework Version:1.1.4322.2300; ASP.NET
Version:1.1.4322.2300 --. For more information, see Help and Support Center
at http://go.microsoft.com/fwlink/events.asp.

--
rvangeldropHello Rvangeldrop,

From your description, you have an ASP.NET web service project which is
reporting the following exception at startup time on a windows 2003
server/sp1 box, correct?

====================
Parser Error Message: The check of the module's hash failed for file
'System.EnterpriseServices.Thunk.dll'.
====================

Based on my experience, since the project is built without problem and the
error occurs at very begining of the appilcation's startup time(intialize
global.asax), it is likely an environment specific issue. Before we perform
detailed troubleshooting, I'd like to confirm the following things:

** Is the webservice project developed upon .net framework 1.1/vs2003 or
..net framework 2.0/vs 2005

** Before deploying on the windows 2003 server/sp1, is it being developed
on another box and works without any problem on it?

** Though the problem is specific to the windows 2003 server machine, you
can still create a very simple webservcie project and test it on the
problem server to see whether the problems also ocurs.

I've also searched some former issues with similar symtom, however, seems
the cause are not quite matching your case. So we need to do some general
problem isolation tests first.

Please feel free to let me know if there is any new finding or any question
you wonder.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscript...ault.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscript...rt/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Hello Rvangeldrop,

How are you doing on this issue, have you got any progress or does the
suggestion in my last reply helps some?

If there is anything else we can help, please feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
the solution was to completely reinstall the server. Appearently some HP
server went bad and this was one of them.

So the problem was at HP for some reason... At least that was what the
customer told me.

--
rvangeldrop

"Steven Cheng[MSFT]" wrote:

Quote:

Originally Posted by

Hello Rvangeldrop,
>
How are you doing on this issue, have you got any progress or does the
suggestion in my last reply helps some?
>
If there is anything else we can help, please feel free to let me know.
>
Sincerely,
>
Steven Cheng
>
Microsoft MSDN Online Support Lead
>
>
This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>

Tuesday, March 13, 2012

Strange problem

I have a class method which takes integer as parameter...when i call the
method as shown below i get this error message: Specified cast is not valid
<td><%# bs.getPriority((int)DataBinder.Eval(Container.DataItem,
"Priority"))%></td>
When i print the DataItem "Priority" it shows an integer value, but for some
reason the method does not like value.. if i call this method like ->
bs.getPriortiy(3); it works fine.
In the database i have a field called "Priority" int type...
The method works fine when i call it in DataItemBound method..
any idea?Hi,
Try using
int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.
Tod Birdsall, MCP
http://tod1d.blogspot.com
Tod thank you so much :) it worked..
still why one of them works not the other as shown below:
<TD><%# bs.getCampusName((int)DataBinder.Eval(Container.DataItem,
"CampusID"))%></TD>
<td><%# bs.getCampusName((int.Parse(DataBinder.Eval(Container.DataItem,
"Priority")))%></td>
both CampusID and Priority is same type of value..
Many Thanks again.
"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Sorry that did not solve the problem... :( i am getting this error message
now:
The best overloaded method match for 'int.Parse(string)' has some invalid
arguments
"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Acutally, DataBinder.Eval returns an object unless you pass a third
parameter, a format specifier, i.e.
DataBinder.Eval(Container.DataItem, "Priority", "{0:d}")
Otherwise you get an object reference back, in which case you could
use Convert.ToInt32
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 9 Nov 2004 07:38:03 -0800, "huzz"
<huzz@.discussions.microsoft.com> wrote:
>Sorry that did not solve the problem... :( i am getting this error message
>now:
>The best overloaded method match for 'int.Parse(string)' has some invalid
>arguments
>"Tod Birdsall" wrote:
>
Hi,
Scott is correct. Sorry for the mis-information.
I tried to reproduce your error message. I created a function in the
code behind like so:
protected string GetRemainderInEscrow(decimal approvedAmount, object
paidAmount)
I then called the method from the aspx page using the following code :
<%# GetRemainderInEscrow( (decimal)DataBinder.Eval(Container,
"DataItem.ApprovedAmount"), DataBinder.Eval(Container, "DataItem.Paid")
) %>
The code worked as it should. If you have control over the
'bs.getPriority' method, try allowing an object to be passed instead of
an integer value type. If that doesn't work. If that still does not
work, copy and paste the exact error message and Stack Trace.
Tod Birdsall, MCP
http://tod1d.blogspot.com

Strange problem

I have a class method which takes integer as parameter...when i call the
method as shown below i get this error message: Specified cast is not valid

<td><%# bs.getPriority((int)DataBinder.Eval(Container.Data Item,
"Priority"))%></td
When i print the DataItem "Priority" it shows an integer value, but for some
reason the method does not like value.. if i call this method like ->
bs.getPriortiy(3); it works fine.

In the database i have a field called "Priority" int type...

The method works fine when i call it in DataItemBound method..

any idea?Hi,

Try using

int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))

DataBinder.Eval returns a string value type. (int) is used to
implicitly cast values to integers. Strings must be explicitly cast
using the Parse method.
Hope this helps.

Tod Birdsall, MCP
http://tod1d.blogspot.com
Tod thank you so much :) it worked..

still confused why one of them works not the other as shown below:
<TD><%# bs.getCampusName((int)DataBinder.Eval(Container.Da taItem,
"CampusID"))%></TD
<td><%# bs.getCampusName((int.Parse(DataBinder.Eval(Contai ner.DataItem,
"Priority")))%></td
both CampusID and Priority is same type of value..

Many Thanks again.

"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Sorry that did not solve the problem... :( i am getting this error message
now:

The best overloaded method match for 'int.Parse(string)' has some invalid
arguments

"Tod Birdsall" wrote:

> Hi,
> Try using
> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
> DataBinder.Eval returns a string value type. (int) is used to
> implicitly cast values to integers. Strings must be explicitly cast
> using the Parse method.
> Hope this helps.
> Tod Birdsall, MCP
> http://tod1d.blogspot.com
>
Acutally, DataBinder.Eval returns an object unless you pass a third
parameter, a format specifier, i.e.

DataBinder.Eval(Container.DataItem, "Priority", "{0:d}")

Otherwise you get an object reference back, in which case you could
use Convert.ToInt32

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 9 Nov 2004 07:38:03 -0800, "huzz"
<huzz@.discussions.microsoft.com> wrote:

>Sorry that did not solve the problem... :( i am getting this error message
>now:
>The best overloaded method match for 'int.Parse(string)' has some invalid
>arguments
>"Tod Birdsall" wrote:
>> Hi,
>>
>> Try using
>>
>> int.Parse(DataBinder.Eval(Container.DataItem, "Priority"))
>>
>> DataBinder.Eval returns a string value type. (int) is used to
>> implicitly cast values to integers. Strings must be explicitly cast
>> using the Parse method.
>> Hope this helps.
>>
>> Tod Birdsall, MCP
>> http://tod1d.blogspot.com
>>
>
Hi,

Scott is correct. Sorry for the mis-information.

I tried to reproduce your error message. I created a function in the
code behind like so:

protected string GetRemainderInEscrow(decimal approvedAmount, object
paidAmount)

I then called the method from the aspx page using the following code :

<%# GetRemainderInEscrow( (decimal)DataBinder.Eval(Container,
"DataItem.ApprovedAmount"), DataBinder.Eval(Container, "DataItem.Paid")
) %
The code worked as it should. If you have control over the
'bs.getPriority' method, try allowing an object to be passed instead of
an integer value type. If that doesn't work. If that still does not
work, copy and paste the exact error message and Stack Trace.
Tod Birdsall, MCP
http://tod1d.blogspot.com