Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

postback happens even when validators show error

Hi,

I am using updatepanel in my code. I give a picture of a part of my code.

Now i have a text box with some validators on it ( required field validator and regular expression validator).

I have a save button which saves the content of the text box .

The textbox is withing the update panel and the save button is outside the update panel.

Now when a wrong iput is entered , on tab out the validator shows the error messgae but on clicking th ebutton , a post back happens. in general case where a update panel is not used the button postback event doesnt happen until the validators return true.

Could you help me on this.

Regards,

Sama

any resolution to this problem yet?

this really needs to be fixed


I also have come across this problem. I have three validators on the footer row of a gridview which is in an UpdatePanel. I use the footer for insertion of new records. When I click 'Insert', the validators fire ok and I get the red asterisks and all but it still posts back. When I take the whole thing out of the UpdatePanel it works as it's supposed to, preventing the postback if no data is entered.

I am using the latest version of Atlas.

Has anyone a solution to this and is it going to be fixed in a future ctp?

Regards,

Andy.


I just investigated further and found the following strage behaviour:

When my page first loads, the gridview is populated with data. The footer is not visible on the gridview as I set ShowFooter() to false by default. There is a button at the bottom of the page "Add Item". This posts back and sets the ShowFooter() to true so that the insert line appears. In this scenario, when the user leaves the new text fields blank, the validator fires but the page still posts back - WRONG.

If I show the footer by default when the page loads, the validators fire correctly and prevent the postback - CORRECT.

Can anyone shed any light on this, I don't want to have my insert line shown by default.

Andy.


bump...

Posting from Tab Control does not work

Hi all,

I am new to AJAXtoolkit and I tried the following code it runs fine but does not input values in textbox nor updates the image

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<script type="text/javascript">
function PanelClick(sender, e) {
}

function ActiveTabChanged(sender, e) {
__doPostBack('<%= Tabs.ClientID %>', sender.get_activeTab().get_headerText());
}
</script>
<div>
<ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="150px"
OnClientActiveTabChanged="ActiveTabChanged"
OnActiveTabChanged="ActiveTabChangedServer">
<ajaxToolkit:TabPanel runat="Server" ID="Panel1" HeaderText="Tab One">
<ContentTemplate>
PAGE ONE - Sample HTML Content for Tab
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel runat="Server" ID="Panel2" HeaderText="Tab Two" >
<ContentTemplate>
PAGE TWO - Sample HTML Content for Tab
</ContentTemplate>
</ajaxToolkit:TabPanel>

<ajaxToolkit:TabPanel runat="Server" ID="Panel3" OnClientClick="PanelClick" HeaderText="Tab Three">
<ContentTemplate>
PAGE THREE - Sample HTML Content for Tab
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer> <br />
<asp:Image ID="Image1" runat="server" />
<asp:TextBox ID="txtTabSelect" runat="server" />
</div>
</form>

in the code behind I have this:

protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Tabs);
}

protected void ActiveTabChangedServer(object sender, EventArgs e)
{
if (Tabs.ActiveTab == Panel1)
{
Image1.ImageUrl = "~/Images/HomeEnabled.jpg";
txtTabSelect.Text = "Selected Panel 1";

}

if (Tabs.ActiveTab == Panel2)
{
Image1.ImageUrl = "~/Images/ProductsEnabled.jpg";
txtTabSelect.Text = "Selected Panel 2";
}

if (Tabs.ActiveTab == Panel3)
{
Image1.ImageUrl = "~/Images/SupportEnabled.jpg";
txtTabSelect.Text = "Selected Panel 3";
}

}

Please do tell me what am I doing wrong. I tried debugging, the watch shows that the values are present but do display.
Thanks,

do you have the autopostback property on the tabs container set to true?


Hi,

ajaxToolkit:TabContainer does not have the property and I did try adding AutoPostBack="true", compiled it and ran but it still does not work. what baffles me is it calls the

protected void ActiveTabChangedServer(object sender, EventArgs e)
{
.....

}

on the server and I can see the values in the watch window but when the page reloads, the values are not there

I have this in the page load event

if (!Page.IsPostBack)
{
ScriptManager1.RegisterAsyncPostBackControl(Tabs);
}

Thanks,


Hi,

It's caused by not calling __dopostback method in a correct way. I suggest using a hidden button to trigger postback. Here is a sample:

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">protected void Page_Load(object sender, EventArgs e) { //ScriptManager1.RegisterAsyncPostBackControl(Tabs); } protected void ActiveTabChangedServer(object sender, EventArgs e) { if (Tabs.ActiveTab == Panel1) { Image1.ImageUrl = "~/Images/HomeEnabled.jpg"; txtTabSelect.Text = "Selected Panel 1"; } if (Tabs.ActiveTab == Panel2) { Image1.ImageUrl = "~/Images/ProductsEnabled.jpg"; txtTabSelect.Text = "Selected Panel 2"; } if (Tabs.ActiveTab == Panel3) { Image1.ImageUrl = "~/Images/SupportEnabled.jpg"; txtTabSelect.Text = "Selected Panel 3"; } //Response.Write(DateTime.Now.ToString()); } </script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <script type="text/javascript"> function PanelClick(sender, e) { } function ActiveTabChanged(sender, e) { $get("<%= Button1.ClientID%>").click();// __doPostBack('<%= Tabs.ClientID%>', sender.get_activeTab().get_headerText()); } </script> <div><asp:Button runat="server" style="display:none;" Text="Button" ID="Button1"></asp:Button> <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="150px" OnClientActiveTabChanged="ActiveTabChanged" OnActiveTabChanged="ActiveTabChangedServer"> <ajaxToolkit:TabPanel runat="Server" ID="Panel1" HeaderText="Tab One"> <ContentTemplate> PAGE ONE - Sample HTML Content for Tab </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel runat="Server" ID="Panel2" HeaderText="Tab Two" > <ContentTemplate> PAGE TWO - Sample HTML Content for Tab </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel runat="Server" ID="Panel3" OnClientClick="PanelClick" HeaderText="Tab Three"> <ContentTemplate> PAGE THREE - Sample HTML Content for Tab </ContentTemplate> </ajaxToolkit:TabPanel> </ajaxToolkit:TabContainer> <br /> <asp:Image ID="Image1" runat="server" /> <asp:TextBox ID="txtTabSelect" runat="server" /> </div> </form></body></html>

Hi Raymond Wen,

I tried your approach too.. but the error occurs again.

It gives me "Microsoft JScript runtime error: 'this.get_element().style' is null or not an object". I dont know what it is and why does it occur as I have not written this piece of code.

upon using a debugger it shows as this "this.get_element().style.visibility = 'visible';" which is present in the

_app_onload funtion like this:

_app_onload : function(sender, e)
{

.... this.get_element().style.visibility = 'visible';

}

Thanks for you help,
Stephen


Can you create a simple page to reproduce it?

Pre-emptive Controls not working

I have installed Atlas the way the documentation says and am using VWD Express.
When I am in code mode, and type in <atlas: it does not pre-emp it and have the controls in the drop down. I'm not sure why? I finish manually entering it in, and receive no error. Not sure why this is doing it. Any ideas, or anyone had similar problems?

Mick

hello.

sometimes it takes a while to initialize the intellisense list here, but then it starts working without any problems.


yes, it does take awhile, today it is working perfectly!!
Thanks,
mick

Monday, March 26, 2012

Preserving the scroll position of a treeview in an update panel

Hi There,

I have a treeview control in a panel with scrollbars. I want to preserve the scroll position and I have this code which works absolutely fine in firefox, but it doesn't in IE. Can somebody please get back to me, if you have experienced this problem and solved it.

Also I noticed that if I put an alert (commented), it works fine, which is absolutely weird.

Thanks a lot!!

<scripttype="text/javascript">

var scrollTop;

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function BeginRequestHandler(sender, args)

{

var elem = document.getElementById('<%= treePanel.ClientID %>');

scrollTop=elem.scrollTop;

}

function EndRequestHandler(sender, args)

{

//alert(scrollTop);

var elem = document.getElementById('<%= treePanel.ClientID %>');

elem.scrollTop = scrollTop;

}

</script>

I noticed one more weird thing. I have roles set up on this application. If a user is in the admin role, this works fine. But if the user is not in that role, then the scrolling is not preserved, whenever a node is selected. I have absolutely no idea why this is happening..This is the case only in IE. Firefox has no problem at all.

Any suggestions are greatly appreciated..

Thanks a lot!!


Change:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

to:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);

and change the name of your function. endRequest happens when control has been returned to the browser, but everything may not have been rendered on the page. Your code is getting ahead of itself.


Thanks a lot for your suggestion. It still doesn't work...thisis what I have..

<scripttype="text/javascript">

var scrollTop;

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoadedHandler);

function BeginRequestHandler(sender, args)

{

var elem = document.getElementById('<%= treePanel.ClientID %>');

scrollTop=elem.scrollTop;

}

function PageLoadedHandler(sender, args)

{

var elem = document.getElementById('<%= treePanel.ClientID %>');

elem.scrollTop = scrollTop;

}

</script>


IE evidently has difficult with scrollTop under certain DOCTYPE definitions.

Replace elem.scrollTop = scrollTop; with

elem.scrollTo(0,scrollTop);


Unfortunately, scrollTo is not recognized in IE 7. I am not sure about IE 6.

As I have mentioned earlier, there is one more weird thing. I have roles set up on this application. If a user is in the admin role, this (script with scrollTop) works fine. But if the user is not in that role, then the scrolling is not preserved, whenever a node is selected. I have absolutely no idea why this is happening..This is the case only in IE. Firefox has no problem at all.

Thanks.


http://www.eggheadcafe.com/tutorials/aspnet/7dd57635-0587-42ba-ae73-f52449e653bf/aspnet-ajax-maintain-scr.aspx

http://forums.asp.net/p/1150033/1873660.aspx

http://aspnet.4guysfromrolla.com/articles/111704-1.aspx

<pages smartNavigation="true"MaintainScrollPositionOnPostback="true"/>

Usually People loves to maintain the scroll postiion. But requirment is reverse, Here is the trick, create an script tag after the scriptmanager and put the following lines:

<script type="text/javascript">var prm = Sys.WebForms.PageRequestManager.getInstance();prm.add_beginRequest(beginRequest);function beginRequest(){ prm._scrollPosition = null;}</script> 

Let me know if this helpful to you


I got this working from the links in the second link you have posted..

I have onscroll="javascript:saveScroll();" on the panel and..

<script type='text/javascript'>
var scrollLeft = 0;

function setScroll()
{
if(document.getElementById('<%= Panel1.ClientID %>').scrollLeft != scrollLeft)
{
document.getElementById('<%= Panel1.ClientID %>').scrollLeft = scrollLeft;
}
}

function saveScroll()
{
scrollLeft = document.getElementById('<%= Panel1.ClientID %>').scrollLeft;
}
</script>

The condition forces the scrolling..

Thanks a lot.

Also thanks to Mr. Budda for his suggestions...

Probelms with Modal Popup via server in code behind

Hi all

I am having problems while adding the modal popup dynamically to my page on the server side on a (web user control). When I set the "TargetControlId" or the "PopupControlId" like this -

ModalPopupExtender modPop = new ModalPopupExtender();
TextBox tbMsg = new TextBox();
tbMsg.ID = "tbMsg";
tbMsg.Text = "Thanks!";
modPop.ID = "modulePopup";
modPop.TargetControlID = hiddenField.ID; //made this hidden field in the user control
modPop.PopupControlID = tbMsg.ClientID;
modPop.BackgroundCssClass = "modalBackground";
modPop.X = 200;
modPop.Y = 200;

Now what is happening is that the ID's that go to the modal popup javascript (ScriptResource etc) I see that it goes in as the name of the textbox itself "tbmsg" instead of the client ID ? so I see something like document.getElementByID("tbMsg") !!!

What am I supposed to do??

Thanks in advance

Sanchita

hiddenField.ClientID will get the ID which is generated by ASP.net

Saturday, March 24, 2012

Problem binding DataTable to ListView using "set_data(result)"

Hello,

I'm calling a web service which is providing a DataTable to my client ASP.NET AJAX javascript code. I'm then trying to bind that data table to a client listview control. The code runs without error message but no results are displayed, despite the datatable having positive content. The problem seems to arise because the "set_data" makes a call to "render" and in that method it checks the validity of "get_length", which the client DataTable does NOT support, so the code falls out to the "Empty Data" template. Basically it seems that ASP.NET AJAX is not expecting to see a DataTable at all, but something else. Can anyone help me with this please?

Here is my page code, the WebService.asmx simply returns a DataTable and "main()" simply wires up the button to kick the process off. the commented code will successfully display the data as an unordered list (simulating a listview):

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="ListViewUnorderedList.aspx.cs" Inherits="ListViewUnorderedList" %>

<!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>
<script>
function main()
{
document.getElementById("btnLoadVendors").onclick = getVendors;
}

function getVendors()
{
var onVendors = function(result)
{

// result is a dataset or data object
var ele = document.getElementById("output");
var ctl = ele.control;
ctl.set_data(result);

/* This would work and do the same job...
ele.innerHTML = "<ul>";
for (var i=0; i<result.rows.length; i++)
{
ele.innerHTML += "<li>" + result.rows[i].Name + "</li>";

}
ele.innerHTML += "</ul>";
*/
}
WebService.getVendors(onVendors);
}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" />
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewGlitz.js" />
<asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewDragDrop.js" />
</Scripts>
<Services>
<asp:ServiceReference Path="WebService.asmx" />
</Services>
</asp:ScriptManager>
<script>
Sys.Application.get_events().addHandler("load", main);
</script>
<input id="btnLoadVendors" type="button" value="Load Vendors" />
<!-- Template for output -->
<div id="output">
Vendor list goes here.
<div style="display:none">
<div id="vendorsLayout">
<ul id="vendorsItemParent">
<li id="vendorsItem">
<span id="vendorsName">Vendor Name goes here</span>
</li>
</ul>
</div>
</div>
</div>
</form>



<script type="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<listView itemTemplateParentElementId="vendorsItemParent" id="output">

<layoutTemplate>
<template layoutElement="vendorsLayout" />
</layoutTemplate>

<itemTemplate>
<template layoutElement="vendorsItem">
<label id="vendorsName">
<bindings>
<binding dataPath="Name" property="text" transform="ToString" />
</bindings>
</label>
</template>
</itemTemplate>

</listView>
</components>
</page>
</script>
</body>
</html>

bump

With hindsight, perhaps I've worded this problem all wrong.

Basically, the "set_data" method of a client control does not accept/understand an ASP.NET AJAX Client datatable object, as I was led to believe it did.

So what object structure do you pass to it?


Well, it looks as if the answer is to pass it the "rows" property of a datatable, this seems to work:

document.getElementById(

"output").control.set_data(result.rows);

Problem calling webservice from client code

Hi All,

I am trying to call a webservice method on a ASP.NET page (in AJAX enabled website). I have my asmx file in the same project as my ASP.NET page. When i try to compile the project , i am getting a "Could not create type TestService" error. Can some body tell me what exactly is the problem here?

Thanks

Mahesh

Confused cud u have given namespace reference of web.script.services.scriptservices

as using web.script.services.scriptservices

& inherite [ScriptServices]


Thanks for the reply ranjeet. But i don't really get the gist of your message , can you please be more clear? I am copying my webservice code below for your reference:

using System;

using System.Web;

using System.Collections;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Web.Script.Services;

using System.Data.SqlClient;

using System.Data;

///<summary>

/// Summary description for TestService

///</summary>

///

namespace MyTestService

{

[WebService(Namespace ="http://tempuri.org/")]

[WebServiceBinding(ConformsTo =WsiProfiles.BasicProfile1_1)]

publicclassTestService : System.Web.Services.WebService

{

[WebMethod]

[ScriptMethod]

publicDataSet GetEmployeeDetails(int empID)

{

String strConnectionString =String.Empty;

String strQuery ="Select * from Employee where EmployeeID = " + empID; ;

strConnectionString ="Server=PC21172\\SQLEXPRESS;Database=EmployeeDB;user=sa;pwd=pwd";

//Get the employee details for the passed id

SqlConnection c =newSqlConnection(strConnectionString);

c.Open();

SqlDataAdapter dataAdapter =newSqlDataAdapter(strQuery, strConnectionString);DataSet dsEmployeeDetails =newDataSet();

dataAdapter.Fill(dsEmployeeDetails);

return dsEmployeeDetails;

}

}

}

Thanks

Mahesh


The DataSet and DataTable is supported in the v1.0. You have add the preview version.


Hi,

I have infact downloaded the January CTP and i am able to return the datatable. Now th issue is , how can i bind the datatable or dataset that i return from the webservice to a ASP.NET datagrid control in javascript call back function. Can somebody help me on this?

Thanks

Mahesh


The Asp.net DataGrid/GridView does not have any objectmodel in the client side. Few days back I wrote a component which does the exact thing, Checkout the following article:http://dotnetslackers.com/articles/ajax/ASPNETAjaxGridAndPager.aspx

Problem Dragging ModalPopupExtender

In the ModalPopupExtender when I drag the popup it always snaps back to the middle.

If I place the JavaScript code that is in the sample page on my page then I am able to drag the popup around the page and it stays where I drop it as expected.

<script type="text/javascript"> // The following snippet works around a problem where FloatingBehavior // doesn't allow drops outside the "content area" of the page - where "content // area" is a little unusual for our sample web pages due to their use of CSS // for layout. function setBodyHeightToContentHeight() { document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) + "px"; } setBodyHeightToContentHeight(); $addHandler(window, "resize", setBodyHeightToContentHeight); </script>

The JavaScript says it's just a work around due to how the sample page is structured. But, in my page I'm not using any type of css layout (other than for the ModalPopupExtender background). I just have a HyperLink, Panel for the popup, Panel for the popup handle and ModalPopupExtender.

<%@dotnet.itags.org. Page Language="C#" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">protected void ButtonOK_Click(object sender, EventArgs e){Response.Redirect("myModal.aspx");}</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Untitled Page</title><style type="text/css">/*Modal Popup*/.modalBackground{background-color: #000000;filter: alpha(opacity=30);opacity: 0.3;}</style></head><body><form id="form1" runat="server"><div><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:HyperLink ID="LinkShow" runat="server">Click to show dialog</asp:HyperLink><br /><br /><br /><asp:Panel ID="PanelPopup" runat="server"><asp:Panel ID="PanelPopupHandle" runat="server">This is the popup handle</asp:Panel>This is the content of the popup panel<br /><asp:Button ID="ButtonOK" runat="server" Text="OK" onclick="ButtonOK_Click" /><asp:Button ID="ButtonCancel" runat="server" Text="Cancel" /></asp:Panel><br /><cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"TargetControlID="LinkShow" CancelControlID="ButtonCancel" Drag="True" PopupControlID="PanelPopup"PopupDragHandleControlID="PanelPopupHandle"></cc1:ModalPopupExtender></div></form></body></html>

Am I missing something or do I need to always place that piece of JavaScript on pages that use the ModalPopupExtender?

this is problem due to not specifying height and width for popup panel
try adding height and width:-

<asp:PanelID="PanelPopup"runat="server"Width="300"Height="300"BorderWidth="1"BackColor="AliceBlue">


Yes, that works. Thank you!


As soon as I click on the dragable header of the ModalPopupExtender popup, the panel moves to the right. It keeps doing this every time I click on it.

I have read every work around on the web to fix this and nothing has worked for me:

1. Added the javascriptsetBodyHeightToContentHeight()

2. Set the Height and Width of the body tag

3. Modified FloatingBahavior.js:

this.onDragEnd =function(canceled) {

canceled =false; <-- added this

4. Set the width and height in the last post.

Nothing has worked for me! Even setting Drag="true" or Drag="false" seems to not work at all.

I could sure use an answer.

Problem forcing an UpdatePanel to post from client-side code (javascript)...

Here's what I'm trying to achieve. I have a rather complex web page that allows data entry. The page utilizes Atlas UpdatePanels for partial reposts. When the user clicks on certain buttons, the data is validated (server-side), and then the user is given the option to save or abandon the changes. To do this, I use RegisterJavaScript to insert a client-side call to a javascript function which calls a vbscript function to display a msgbox (we're only using IE). The vbscript function returns the msgbox value back to the javascript function which then sets an ASP HiddenField. The next step is where I'm having problems. I need the javascript function to force a partial postback so that the server-side code can evaluate the msgbox results (in the hidden field), and respond accordingly. I don't want to repost the entire form because I loose data from other asynchronous client-side page modifications.

So the real question is; how can I force an UpdatePanel to post from client-side code? I've read a number of other threads on this subject and a suggested solution is to call the click event of a hidden LinkButton within the UpdatePanel. So I tried this and it worked! At least it worked for a while. This is the most frustrating part. At some point, and I have no idea what changed to cause this, the code stopped working. Now, when I call the click event, I get an undefined error in the doPostBack function and the form will no long post at all.

If anyone has any suggestions on what is causing this problem, or a better way to force an UpdatePanel to partial post, it would be greatly appreciated!

Here's some of my code;

<atlas:UpdatePanel ID="upConfirmActivitySave" runat="server" Mode="conditional"><ContentTemplate> <asp:HiddenField ID="hfConfirmActivitySave" runat="server" /> <asp:LinkButton ID="lnkDoPostBack" runat="server" style="display:none"></asp:LinkButton></ContentTemplate></atlas:UpdatePanel><script language="javascript" type="text/javascript"><!--function confirmActivitySave() { document.getElementById('hfConfirmActivitySave').value = ConfirmActivitySaveMsgbox(); document.getElementById('lnkDoPostBack').click();} // --></script><script language="vbscript" type="text/vbscript"><!--Function ConfirmActivitySaveMsgbox()'This only works for IEConfirmActivitySaveMsgbox = MsgBox("Do you wish to save?",35)End Function// --></script>

I decided to simplify things and created a new aspx page with a single UpdatePanel and two ASP ImageButtons, one inside the UpdatePanel and the other outside the UpdatePanel. The client-side code for the button outside the UP calls the click method for the button inside the UP. And sure enough, I get a partial post. So this tells me there's something wrong with my main project page. I wonder if I've hit some sort of atlas bug or limitation?


This just gets weirder and weirder. I restored my project to a prior version – one that the partial post code still worked. I compared the differences in the html between the working and non working versions and the only changes were some controls that were renamed (all within UpdatePanels) and a single control (an asp:HyperLink) that moved from outside to inside an UpdatePanel. So, from the working code, I moved the one control (using cut/past) and sure enough the page fails during the client-side partial post; "unknown runtime error". And get this; if I delete the control, the page still fails. By the way, all references to this control (client-side and server-side) have been removed. Essentially, the control is unused. But if I delete it, the page fails. What gives? I can remove other controls, or add and remove controls with no problem. It's almost like there's some reference that's not getting deleted correctly. Any ideas? Anyone?

Problem getting elements by ID inside <Content> of AccordionPane

Dear All,

I've got problem on changing the content inside a <div> element inside the Content part of AccordionPane. The code is below:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<script type="text/javascript">

function test1(){

var table = document.createElement('TABLE');
table.setAttribute('border',0);
table.setAttribute('id','sliderTable');

var tBody = document.createElement('TBODY');
table.appendChild(tBody);

var row = document.createElement('TR');

var cell = document.createElement('TD');

cell.style.backgroundColor = "#CCCCCC" ;
cell.style.width = 10+ "px";
cell.style.height = 5+ "px";

row.appendChild(cell);

tBody.appendChild(row);
}
document.getElementById('colorTable').appendChild(table);

document.getElementById('colorTable').style.display='';

}

</script>

<asp:ScriptManager id="ScriptManager1" runat="server" />

<ajaxToolkit:Accordion ID="Accordion1" .....>

<Panes>

<ajaxTookit:AccordionPane...>

<Header>Color</Header>

<Content><div id='colorTable' style="display:none"></div><Content>

</ajaxToolkit:AccordionPane>

......

</Panes>

</ajaxToolkit:Accordion>

</asp:Content>

When I run the code it said there is a javascript error "Object Required". It is the script cannot locate the 'colorTable' element? And what way can I locate the element?

Thanks!!

Stard

Hello,

As you propably discoveredSmile:

function test1(){

var table = document.createElement('TABLE');
table.setAttribute('border',0);
table.setAttribute('id','sliderTable');

var tBody = document.createElement('TBODY');
table.appendChild(tBody);

var row = document.createElement('TR');

var cell = document.createElement('TD');

cell.style.backgroundColor = "#CCCCCC" ;
cell.style.width = 10+ "px";
cell.style.height = 5+ "px";

row.appendChild(cell);

tBody.appendChild(row);
} <----- syntax error
document.getElementById('colorTable').appendChild(table);

document.getElementById('colorTable').style.display='';

}

has syntax error, there is an unnecessary } /or your copy/paste was not successful/


Hi stmarti,

sorry I've got typo error in my post :) Since I just type the main structures of my code and my original one haven't got this typo error.

Btw I searched some other forum and got some solutions like document.getElementById('<%colorTable.ClientID%>') because I am working with a content page under a master page. But I get "colorTable do not have the ClientID property" error.

Any idea on this?

Many thanks.

Stard


Hi,

I have some comments maybe it helps:

a) the correct syntax is <%= colorTable.ClientID %> or <%# colorTable.ClientID %>

but I think it is unnecessary, because your div isnot a server side control so it's id won't be altered! This is only necessary when you have:

<div id='colorTable' style="display:none"runat="server" ></div>

b) The really big problem is style="display:none"andthe empty div.

Why? Because with this style yourempty div will not ever rendered in the browser(!!!) and not even part of the DOM tree! Just check this.

Try instead of: strip style="display:none" or change it style="visibility: hidden;" or use a span instead of div as a placeholder or put some content in the div. Try all these to understand how your browser render empty or display:none divs.



Hi,

Small update, start here: change your div to

<div id='colorTable' style="display: none;"> </div>

and document.getElementById( 'colorTable' ) should worksSmile

problem in ajax

i am using the below code to initialize the xmlhttprequest


try
{
obj = new XmlHttpRequest();
}
catch(e)
{
try
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e1)
{
obj = new ActiveXObject("Msxml2.XMLHTTP");
}
}
 it works fine in my system. but when accessed from network, the ajax features
doesnt work. I have placed the code for ajax and some validation
scripts in the .js file. The validation scripts works fine, but not the
ajax scripts.

Please give me solution...Its urgent.

Confused

try this url

http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/

This will help you to create a XmlHttpRequest Object which is supported by all browsers.

Wednesday, March 21, 2012

Problem in export data from DataSet to Excel

I am using Ajax in my application......

my code will execute properly in normalwebform....

My Code:

publicvoid ExportTOExcel(DataSet ds,HttpResponse res)

{

this.Response.Clear();

this.Response.Charset ="";

this.Response.ContentType ="application/vnd.ms-excel";

System.IO.StringWriter sw =new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter hs =newHtmlTextWriter(sw); DataGrid dg =newDataGrid();

dg.DataSource = ds.Tables[0];

dg.DataBind();

dg.RenderControl(hs);

this.Response.Write(sw.ToString());

this.Response.End();

}

when i execute the same code inajax webform it show me following error.....

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, HttpModules, or server trace is enabled.
Details: Error parsing near '<table cellspacing="".

reply me ASAP........

Hi

I think the error message explain the issue clear.

You cann't modifiy response by calls to Response.Write(), response filters, HttpModules when you use AJAX. The message received from the server could not be parsed.


Then how to solve this problem do you any alternate solution for this error.........

send me any sample code...........

Please reply ASAP.


I'm experiencing the same issue. Found this article it will help you to understand some of the issues involved...http://mattberseth.com/blog/2007/07/indepth_the_updatepanel_aspnet.html

Mind you I haven't resolved the problem as yet, but it did take me one step closer.... so if any one find a solution please post.

Problem in ListBox double click in UpdatePanel

Hi,

I have a problem in add ListBox double click in UpdatePanel. Now, my code works well.(It is the solution online) But when I put the ListBox in UpdatePanel, it also refresh the whole page, not AsyncPostBack...The dblclick is in Javascript, I don't how can it also work fine with AJAX. Thanks!

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %
<!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>
<script language="javascript">
function ListBox1_DoubleClick() {
/* we will change value of this hidden field so

that in
page load event we can identify event.
*/
document.forms[0].ListBox1Hidden.value = "doubleclicked";
document.forms[0].submit();
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div>Double click on Listbox
<br />
<asp:ListBox id="ListBox1"
ondblclick="ListBox1_DoubleClick()" runat="server">
<asp:ListItem Value="1">One</asp:ListItem>
<asp:ListItem Value="2">Two</asp:ListItem>
<asp:ListItem Value="3">Three</asp:ListItem>
<asp:ListItem Value="4">Four</asp:ListItem>
</asp:ListBox>
<input type="hidden" name="ListBox1Hidden" />
</div>
<div>click on button
<br />
<asp:Button id="Button1" onclick="Button1_Click"
runat="server" Text="Button"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>


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

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Request.Params["ListBox1Hidden"] != null
&& (string)Request.Params["ListBox1Hidden"] == "doubleclicked") {
//This means It was double click
Response.Write("Double Click was fired selected item is "
+ ListBox1.SelectedItem.Text);
}

}
protected void Button1_Click(object sender, EventArgs e)
{

}
}

I think you should enablepartialrendering property of the ScriptManager.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnablePageMethods="true">

Still not working.......any another idea? Thanks

codeasp:

I think you should enablepartialrendering property of the ScriptManager.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnablePageMethods="true">


Instead of calling submit on the form, try __doPostBack('<%= UpdatePanel1.ClientID %>', '');


Thank you so much! It works now.

problem in using AJAX

i am using visual web developer 2005 and SQL Express 2005 with VB as the code behind

i have created a web site using ASP.NET Web Site installed template

now i want to add AJAX to my web site .

i have downloaded the AJAX December CTP and installed and it is working fine with newly created website using the ASP.NET AJAX CTP-Enabled WebSite template

is it possible to convert my existing web site to use AJAX or should i do it from the beginning

please help me

You can convert the website to use Ajax from an Atlas CTP. This guide should help.

http://ajax.asp.net/documentation/Migration_Guide_CTP_to_RTM.aspx

problem of UpdatePanel with legacy code

The page has UpdatePanel control also has many custom controls written under aps.net 1.1. After use command 'iisrestart', the respones of the first time access is correct. UpdatePanel works very well. But when we access the site again, there will be some 'access denied' exceptions. and UpdatePanel cann't work correctly. The page still refreshs when submit something in UpdatePanel.

Thanks

Update Panel only work with the xhtml transitional code. Configure your web config file from legacy to transitional
but the first access is currect after restart IIS server. how to explain it with you theory? in my opinion, it may because of cache or some related things, doesn't it?

thanks, i'v solved it. change <xhtmlConformance mode="Legacy"/> to <xhtmlConformance mode="Transitional"/> .

this article makes it clearhttp://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx