Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, March 28, 2012

PostbackAction ???

How the heck does one go about using the PostbackAction in javascript? I can't find anyone who is successfully using it in javascript.Hi,

please check this example:

<%@. 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) { // This will drop the __doPostBack function on page. Page.ClientScript.GetPostBackEventReference(this, String.Empty); if (Page.IsPostBack) { lblTarget.Text = Request.Form["__EVENTTARGET"]; lblArgument.Text = Request.Form["__EVENTARGUMENT"]; } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <atlas:ScriptManager ID="sm" runat="server"></atlas:ScriptManager> <div> <input type="button" id="myButton" value="ClickMe" /> <br /> <span>Postback target: </span> <asp:Label ID="lblTarget" runat="server"></asp:Label> <br /> <span>Posback argument: </span> <asp:Label ID="lblArgument" runat="server"></asp:Label> </div> </form> <script type="text/xml-script"> <page> <components> <application load="application_load" /> </components> </page> </script> <script type="text/javascript"> function application_load() { var myButton = new Sys.UI.Button($('myButton')); myButton.set_id('myButton'); myButton.click.add(Function.createDelegate(this, clickHandler)); myButton.initialize(); function clickHandler(sender, e) { var postBack = new Sys.WebForms.PostBackAction(); postBack.set_target(sender.get_id()); postBack.set_eventArgument('myArgument'); postBack.performAction(); } } </script></body></html>

If you need only to cause a post back use this line in your javascript code:

__doPostBack();

If you need data from your client script code then use this:

__doPostBack('X','Y');

X --> This is some name you make up that allows you to identify what caused the post back on the server-side code.

Y--> This is the data you are passing back from your javascript. If you need more than one value passed back just separate the values with a comma or something. ie. '42,53' Then you can separate the string in your server side code.

The Server Side of things.

If you are only causing a post back then you don't need to worry about any server-side code. If you did pass data back put the following code in your Page_Load event and use the If statement to see what fired the post back since other controls will also use the javascript post back.

If Request.Form("__EVENTTARGET") = X Then

dim s as String = Request.Form("__EVENTARGUMENT")

'do something with your data

End IF

Hope this helps.


hello.

btw, x is normally used for sending the client id of the server side control that started the postback and y is used to send info associated with that action. for instance, if you have a button which has id bt, setting x to bt will automatically invoke a previouslly configured method on the server which was configured to handle the click event of that button.

postbacks and ajax

I have created dynamic datagrid with vb.net using (no javascript) that has checkboxes and dropdowns, and when checkboxes checks it postsbacks, and shows data comes from database, now I want no postbacks to happen. I guess I can do that in ajax, but need a help on it, since I have never done that before and don't know ajax. Can anybody help me on that?

Hi There,

If you are using .net 2.0 with ajax.net

Try following, this is do a callback when you click on your checkboxes

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

<asp:UpdatePanelID="updatepanel1"runat="server">

<ContentTemplate>

YOUR DATAGRID HERE

</ContentTemplate>

</asp:UpdatePanel>


I am using 1.0 and didn't work on that, I need 2.0 then? Do I need to start with ajax enable website or can I add it those lines later to existing project ?


actually my asp.net version 2.0, but ajax 1.0


Check out all the vid's on ASP.NET AJAX:

http://www.asp.net/learn/videos/default.aspx?tabid=63

This one in particular should help:

http://www.asp.net/learn/videos/view.aspx?tabid=63&id=75

This one discusses what is needed to use ASP.NET AJAX with an existing application:

http://www.asp.net/learn/videos/view.aspx?tabid=63&id=81


Unfortunately I cannot view videos, it says respond denied.


What d4dennis@.inspir3 said should work but you have to add somestuff to your web.config file before the site is "ASP.NET AJAXenabled".


This goes under the <configuration> tag

  <configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

 This goes inside the <pages> tag:
  <controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>

If you haven't made any changes to your <compilation> section replace it with this: (Otherwise change it accordingly)
  
<compilation debug="false">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>


  Finally add this just above the </configuration> tag:
 
 <system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->
<!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2" />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true" />
-->
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>

Hope this helps!


Thank you for laying out this for me, I just found the same thing right before you have sent me and implemented, so web.config is fine now, but in my existing project , I have lots of panels, tables etc. and I tried to put my datagrid inside the this format

<body> <formid="form1"runat="server"> <asp:ScriptManagerID="ScriptManager1"runat="server"/> <asp:UpdatePanelID="UpdatePanel1"runat="server"> <ContentTemplate> <div>

datagrid

</div> </ContentTemplate> </asp:UpdatePanel> </form></body>

which I don't want it to refresh whole page is working but it is something weird happening inside the my grid, I have checkbox and dropdown and textboxes right, when I checked the checkbox, page is not refreshing which is Good, what I want, but because I need to enable dropdown when checkbox checked, refresh happening inside the grid to dropdown, I wonder if I put my updatepanel and contenttemplate to right place or not?


I need when checkbox checked inside the grid, my dropdown inside the grid should enables, gets filled with data without refreshing the page or datagrid. Right now, it is not refreshing the page but inside the grid almost like part of the grid where dropdown there gets refresh( looks like flashing at that area where dropdown sits) I don't want that.

I wrote a lot of working code (at SERVER SIDE) didn't use javascript that does things inside the datagrid when user checks checkboxes. But it was keep refreshing the page with each checkbox clicks that's why I need to use ajax.

Monday, March 26, 2012

PRM_ParseErrorDetails null or not an object.

I'm getting the following javascript error in my page whenver i try to use an UpdatePanel:

"Sys.WebForms.Res.PRM_ParseErrorDetails is null or not an object."

I have the RC1 dll in my bin folder, all the relevant entries in my web.config, and this worked fine before, but suddenly it's gone kaput!

Any help would be great.

Can you repro this error again? Try to post some codes?to?repro?this?error here.
Try to debug javascript error according to the following steps.
Steps:
1.Create a file based web site
2.Add a JavaScript file called MyScript.js to the root of the project
In this file, add the following:
function MyCustomFunction()
{
//doing custom work
alert("MyCustomFunction ran!!!");
}
if (typeof('Sys') !== 'undefined') Sys.Application.notifyScriptLoaded();
3.Add an ASPX page to the application
4.Add a ScriptManager to the page and add the above script the Scripts collection
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/MyScript.js" />
</Scripts>
</asp:ScriptManager>
5.Ensure that the Disable Script Debugging options are unchecked in Internet Explorer's Advanced Properties.
6.Set a breakpoint on the alert("MyCustomFunction ran!!!"); line in the MyScript.js file
7.Ensure that Internet Explorer is configured for debugging using information from this lesson
8.Press F5 to start debugging.
Does the breakpoint get hit?
Which processes does Visual Studio attach to? (hint: check Debug | Attach to Process..)
9.Add the following HTML to the <body> of the ASPX page:
<input type="button" value="Call Function" onclick="MyCustomFunction()" />
10.Press F5 to start debugging.
Does the breakpoint get hit?
Which processes does Visual Studio attach to? (hint: check Debug | Attach to Process..)
11.Add each item listed below after the alert(); in MyCustomFunction() one at a time and Press F5 to debug the page. i.e. Add item "a" from the list, press F5. Remove item a and add item "b" and repeat. Answer the following:
Does the breakpoint get hit?
Which processes does Visual Studio attach to? (hint: check Debug | Attach to Process..)
a.debug.assert(false, "That wasn't supposed to happen!", true);
b.debug.fail("Did I break?");
c.debug._traceDump(Sys.Application, 'object name', true, '... ');
d.debug.trace("Is this a trace or what?");
12.While you're attached to the iexplore.exe process, take a look at the Script Explorer (Debug menu, Windows, Script Explorer).

Wish the above can help you.

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 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 for calling Method in Javascript

My code:

<

atlas:ScriptManagerID="scptManager"runat="server"><Services><atlas:ServiceReferenceGenerateProxy="true"Path="~/adm/AddEditCustomFieldDataService.asmx"Type="AddEditCustomFieldDataService"/></Services></atlas:ScriptManager></form><scriptlanguage="javascript"src="../ClientIncludes/Jscript.js"type="text/javascript"></script><scripttype="text/javascript"language="javascript">var strMessages="";var bLock;function DeleteCustomDataFieldLookUpValues()

{

var intValueId;

intValueId=document.AdmCustomDataFieldLookupListForm.txtPageTarget.value;

strMessages=

"";

AddEditCustomFieldDataService.ADMCheckCustomFieldIsInUseorNot(

'0',intValueId,CallBackADMCheckCustomFieldIsInUseorNot);

}

}

function CallBackADMCheckCustomFieldIsInUseorNot(args,context)

{

---

}

This working fine in my pc but in another pc its show script error 'AddEditCustomFieldDataService is undefined'

What are the system requirements for atlas? I installed the atlas .Whether JVM need?

Hi,

did you upload the AddEditCustomFieldDataService.asmx to the other pc? Does it have the same Path as in your pc?

It is same path as Page exist .And it work well on other pc and developed pc but not some other pc's

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?

Wednesday, March 21, 2012

Problem in finding dynamically loaded user control in javascript when using ASP.Net AJAX

Hi,
I am loading user controls dynamically in an update panel. User control loads smoothly, but when i viewsource the page, the current loaded user control can't be found there. What I found is old user control which loads when page is loaded for the first time. I have a grid view control in that user control which i want to validate using javascript, but this grid view control can't be found by javascript 'getElementById' function. How can i access grid view and other controls in javascript?

Thanks in advance.
Regards

Amjad Paracha, MCP
Software Engineer.

Seehttp://forums.asp.net/t/1149634.aspx

My guess is that your ID is incorrect when you are trying to access the control.

-Damien


amjad.paracha:

Hi,
I am loading user controls dynamically in an update panel. User control loads smoothly, but when i viewsource the page, the current loaded user control can't be found there. What I found is old user control which loads when page is loaded for the first time. I have a grid view control in that user control which i want to validate using javascript, but this grid view control can't be found by javascript 'getElementById' function. How can i access grid view and other controls in javascript?

Thanks in advance.
Regards

Amjad Paracha, MCP
Software Engineer.

What you are experiencing is the reality of how a browser actually works. The source code that you download on page load is not fixed. Its image in browser computer memory can be altered dynamically (especially by Ajax updates) and that is why the source does not reflect it. If you want to see much more closely what is going on in the page, download and install the IE Developer Toolbar (or another browser DOM viewer). This will show the current DOM and you may in fact find that the Id you are looking for is either not there or it is set as a ClientID (a property of most controls) which does not match the original ID. This would be true for instance of any ordinary control in a tab panel. They will not have the same ID you assigned on the server. As well any control in a repeating control will be assigned a new client id.

AFAIAC every develper that develops without a tool that can see the DOM as it exists is working blind. As a bonus, the IE Developer Toolbar has the ability to modify styles on the fly so you can see what they do, trace styles and a few other things.

Problem on creating popup window with ajax

Hi ,

I want to create a popup window when i select ' add new' in dropdown list. I am using javascript for opening popup window and to bind dropdown list details im using AJAX. The problem here is popup window is not opening with ajax. Without ajax it is opening.Why? ( Iam using asp.net2.0 version)

Thanks.

Make sure you're using ScriptManager.RegisterStartupScript to register your popup script. Take a look here for an example: http://encosia.com/index.php/2007/06/19/the-easiest-way-to-break-aspnet-ajax-pages/


Hi,

I try to insert the bellow method insted of responce.write()

Page.ClientScript.RegisterClientScriptBlock("","","") in my code, But it showing an error of parameter 'type' I used type=me.gettype() method.

Any idea how to pass parameters?

Thanks,

Aswath.


Make sure you use the ScriptManager method, not the ClientScript one, if you want to use it in a partial postback.


Hi all,

I can able to create popup window as well as closing it autometically, But the problem is after closing popup window i want to display the value in parent window.Can anybody help me...? In popup window one dropdown list was there iam storing that value(what i entered in dropdown) in database after that window is closing autometically.Now i want to display that value what i stored in database in my parent window's dropdown list.

plz help me ....

Aswath.