Wednesday, March 21, 2012

ascx and ajax

HTML Source EditorWord wrap

Hi!

I am using an chat control (ascx) on my aspx sites. Any user can post a message and press the 'Absenden' button. After that the message will be send to database through code behind. The Gridview will be updated after this. Now I am trying to change the code (to ajax) so that there is 'no' postback on clicking on the 'Absenden' button. I have just watched the video on introducing ajax and sofar i am not quite sure what to do - placing a script manager ? placing an update panel? Thanks in advance for your help!!

ASCX Code

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="ajaxLaberbox.ascx.cs"Inherits="Steuerelemente_laberbox" %>
<%@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>
<tableborder="0"width="150">
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<tdclass="ueberschrift3"align="center">Die LOW-Laberbox</td>
</tr>
<tr>
<tdheight="1"> </td>
</tr>
<tr>
<tdheight="1">
<asp:LabelID="lblNachricht"runat="server"Text="Deine Nachricht"CssClass="ueberschrift3"></asp:Label>
</td>
<tr>
<tdalign="center"height="1"><asp:TextBoxID="txtNachricht"runat="server"Height="87px"BorderColor="Transparent"ForeColor="Black"TextMode="MultiLine"MaxLength="400"Width="160px"></asp:TextBox>
</td>
</tr>
<tr>
<tdalign="center"height="1"><asp:ButtonID="btnAbsenden"runat="server"Text="Absenden"BackColor="#EDC112"BorderWidth="0px"Font-Names="Tahoma"Font-Size="8pt"OnClick="btnAbsenden_Click"/>
</td>
</tr>
<tr>
<tdnowrap>
<asp:GridViewID="gvNachrichten"runat="server"AutoGenerateColumns="False"DataSourceID="dbNachrichten"GridLines="None"Width="175px">
<Columns>
<asp:BoundFieldDataField="text"HtmlEncode="False"SortExpression="text">
<ControlStyleWidth="150px"/>
<ItemStyleWidth="150px"Wrap="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="dbNachrichten"runat="server"ConnectionString="<%$ ConnectionStrings:dbLOWConnectionString %>"
SelectCommand="SELECT top 10 '<span class="ueberschrift3">' + benutzer + ': </span><font size="-2" color="#EDC112">(' + DATENAME(d, datum) + '.' + convert(varchar(3), DATEPART(m, datum)) + '. ' + DATENAME(hh, datum) + ':' + DATENAME(mi, datum) + ')</font><span class="normal"> ' + nachricht + '</span>' AS text FROM tblNachrichten order by id desc">
</asp:SqlDataSource>
</td>
</tr>
</table>

The page that contains that control will need to have scriptmanager tag in it. The contents of your control (After the <%@. Register %>) need to be in an update panel of its own or you could place the control in an update panel inside of the Page.

Here is a link to some code to paste inside of the control that will dynamically add a scriptmanager and add all of the controls contents to an update panel.http://forums.asp.net/t/1090648.aspx?PageIndex=2


I found the problem! Unfortunatelly it was something completly different. My project was a simple ASP.Net Website. So in myweb.configmissed all necessarytags for ajax (see below)!! Thx to Joseh Humphrey - additionally i had to add the script manager in the page not in the control!

<config section>
<httpHandlers>
<system.webServer>
and so on

IT WORKS! :-)

No comments:

Post a Comment