Wednesday, March 28, 2012

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.

No comments:

Post a Comment