Showing posts with label populated. Show all posts
Showing posts with label populated. Show all posts

Monday, March 26, 2012

Chanage button visibility if the button is outside of the UpdatePanel

Hello everyone,

Here is my scenario, and my problem.

I have a grid inside an UpdatePanel_1. The grid is populated after a Search button inside another UpdatePanel_0 is clicked (this is actually an user control and UpdatePanel_0 is inside the user control). This works fine.

I want to provide an Export button which exports the data from the grid to Excel, but want to show it only if the grid has any records.

If I add the button to UpdatePanel_1 the visibility toggling works fine, but when I click on the button I get the nasty message:

"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, HTTP modules, or trace is enabled... "

And of course, I am using Response.Write for the Export of the grid to Excel.

If I put the Export button out of UpdatePanel_1, the Export works fine, but I cannot find a way to toggle the visiblity of the button. I set the visibility in the code behind when the grid has some records, but it doesn't seem to work (probably because the button is outside of the UpdatePanel_1).

What should I do to make the Exprot work and the button to appear only when I want it?

Thank you!

You could add the button to the UpdatePanelGridView and add an async trigger for the gridview databind event. So on databind, if gridview is empty your button will not show.


Hi Denis,

Thank you for your reply.

Setting the visibility of the button is not a problem when the button is inside the UpdatePanel. The problem in this case is that Export to Excel, which has to happen when the user pushes the button, doesn't work because of the error mentioned above (and the reason for the error is the Response.Write statement in the function below).

If I put the button out of the UpdatePanel, the Export to Excel works, but I have no control over the button's visibility, because it depends on the GridView records, which is inside an UpdatePanel.

Here is the function I use for the Export:

Public Sub ExportGridToExcel(ByVal grvBusinessAs GridView,ByVal pageAs Page,ByVal fileNameAs String)If grvBusiness.Rows.Count.ToString + 1 < 65536Then Dim twAs New StringWriter()Dim hwAs New System.Web.UI.HtmlTextWriter(tw)Dim frmAs HtmlForm =New HtmlForm() page.Response.ContentType ="application/vnd.ms-excel" page.Response.AddHeader("content-disposition","attachment;filename=" & fileName &".xls") page.Response.Charset ="" page.EnableViewState =False page.Controls.Add(frm) frm.Controls.Add(grvBusiness) frm.RenderControl(hw) page.Response.Write(tw.ToString()) page.Response.End()End If End Sub
I am still new to AJAX so little things like this are not easy to solve.Wink

Saturday, March 24, 2012

CascadingDropDownList and ModalPopupExtender

I have created a ModalPopupExtender that contains 3 CascadingDropDownLists. The dropdowns work and are populated normally if I don't try and set a value. If I try and set a value for the first dropdown I get an ArgumentOutOfRangeException error. It seems like the value is trying to be set before the dropdown is populated. Does anyone know how I can fix this?

Thanks.

Nevermind. I got it.

CascadingDropdownList [Method Error 500]

Still trying to get these dropdowns to work. I have created a page with a single ddl that should be populated from the web service and has no parents but I still get the [method error 500] as the values, what am I mising here?

ddl.aspx

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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">
<asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>

<asp:DropDownList ID="Region" runat="server" >
</asp:DropDownList>

<cc1:CascadingDropDown
Category="Region"
Enabled="true"
PromptText="Please work..."
ID="CascadingDropDown2"
TargetControlID="Region"
ServiceMethod="GetCountries"
ServicePath="CountriesByRegion.asmx"
runat="server">
</cc1:CascadingDropDown>

</form>
</body>
</html>

CountriesByRegion.asmx

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports PFCEnergy.Refining.Country.Business
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Shared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class

Hi,

I too get the same error . Have you sorted the problem ?

Pls help if its working for u .

Thanks.


Yeah got it working, I added the bold and removed the struck through. Good luck.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
PublicShared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class


Hi,

Iam not using list as u did in web method, So i thinkImports System.Collections.Generic is not needed.

Then i am not using Static (C#) in function.

So what would be wrong in my case?

Thanks.



Hi everyone, I had the same problem and after a little tweaking it works!

Here is the tip:

Please make that the database datatype matches the .NET datatype.If you have a different datatype in your database, you should TYPE CAST it to the corresponding .NET type.
string make = (string)dr["Make"];
int makeId = (int)dr["MakeID"];

.NET Framework Type

ADO.NET Database Type

SQL Data Type

String

Varchar

Varchar()

String

Nvarchar

Nvarchar()

String

NChar

Nchar()

String

NText

NText

String

Text

Text

Double

BigInt

Float

DateTime

DateTime

Datetime

DateTime

SmallDateTime

Smalldatetime

Int

Int

Int

Int64

BigInt

Bigint

Int16

SmallInt

smallint

Byte[]

Binary

Binary()

Byte[]

Image

Image

Byte[]

VarBinary

Varbinary()

Byte

TinyInt

Tinyint

Bool

Bit

Bit

Decimal

Decimal

Decimal

Decimal

Money

Money

Decimal

SmallMoney

SmallMoney

Float

Float

Float

Guid

UniqueIdentifier

Uniqueidentifier

Real

Real

Real