Wednesday, March 28, 2012
AJAX becomes full postback in IIS
<div>
<asp:UpdatePanel ID="upnlServerTime" runat="server">
<ContentTemplate>
<asp:Label ID="lblServerTime" runat="server" Text="Server Time"></asp:Label>
<asp:Button ID="btnServerTime" runat="server" Text="Get Server Time" OnClick="btnServerTime_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnServerTime" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
Behind Code:
protected void btnServerTime_Click(object sender, EventArgs e)
{
Label lblServerTime = upnlServerTime.FindControl("lblServerTime") as Label;
lblServerTime.Text = DateTime.Now.ToLongTimeString();
}
I doubt you don't create web application when you create a virtual directory in IIS.Right mouse click virtual directory in IIS and select Properties,Click "Create" button to create application name and Choose Execute Permission for "Scripts only" or "Scripts Executable" from permission DropDownList.Try to addNetwork Service to virtual directory?when?deploying?Ajax?
website.
Wish this can give you some ideas.
Monday, March 26, 2012
AJAX autocompleteextender
Hi All,
I am using the autocompleteextender and I am wondering if there is anyone you can click on an option from what it returns to redirect it to another page.
Is this possible?
Thanks
You could use AutoComplete's ItemSelected event in the client and then navigate to another page using JavaScript.Alternatively, if you have a button that the user usually clicks on to submit the page, you could do the following in the same script:
$get("btnSubmit").click();
This will send a click event to the button and submit your page as normal.
Tim
ajax animation extender
hi..
im new to asp ajax..i created image dynamically...and if i click the image panel should be displayed by using animation extender..
i have to write the animation extender in java script...by getting the image ID from code behind...is it possible...
Hi Rajukv,
I think you should better set the AnimationExtender's TargetControlID on the server side. For 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) { Image myImage = new Image(); myImage.ID = "myimage"; myImage.ImageUrl = "~/pic/upg_HomeBasic.jpg"; this.Panel1.Controls.Add(myImage); this.AnimationExtender1.TargetControlID = "myimage"; }</script><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"> </asp:ScriptManager> <asp:Panel ID="Panel1" runat="server" Height="300px" Width="600px"> <ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server"> <Animations> <OnHoverOver> <Parallel Duration=".1" fps="50"> <Resize Width="250" Height="250" /> </Parallel> </OnHoverOver> <OnHoverOut> <Parallel Duration=".1" fps="50"> <Resize Width="50" Height="50" /> </Parallel> </OnHoverOut> </Animations> </ajaxToolkit:AnimationExtender> </asp:Panel> </form></body></html>I hope this help.
Best regards,
Jonathan
Thank u Jonathan .
i got it by using ModelpopUp with animation...by taking Modelpopup TargetControlID=hiddenbutton
Saturday, March 24, 2012
AJAX and using the onbeforeunload event
When my form loads I set a variable in the database to lock the form. Only one user at a time can edit/view the form. When they click the Save button I remove the flag via a database query and the form is no longer locked. This works great when the user clicks the Save button. But what do you think happens when they do not click the Save button and they leave the page? Since no button on the form was pushed I cannot update the database to unlock the form. So I thought of using the onbeforeunload event. I am using it now to tell the user that if they leave the form before they click the Save button their data will be lost. What I would like to be able to do is when the user does click the OK button on the alert box and they do leave the form I would like to run a sql statement to update the database and to unlock the form. Is this do-able? With or without AJAX?
Just theorizing... but since you succesfully have the alert box going - on the unload event.. can you tie up an asynchpostback event in javascript to handle this - once the request is fired all should be good (the migration guide has some examples of this I believe...) or as an alternative you can popup a modal (however at that point the user can just hit the back button again anyways)...
For a double measure - either use an event timer in the global.asax that call the stored procedure. One additional field in the database would be needed "TimeofRecordLock"... and modify the sp to search for all records that time expired from initial lock that excedes your lock time... get reset... Any postbacks that occur just have the sp that does whatever or the code behind itself to update the new time value... - then you could have a special updatepanel that is set to refresh on a timer - "Record is locked" kinda of deal - when timer expires and no updates have been made - it provides another option - "re-lock record"... if it trys to and another user grabbed it then it reverts to a option - notify me when record is unlocked... The cool thing about ajax you can make that happen and the user really needs to not do anything...
You could also create a cache that that stores the time and you update the time in cache and map it to the session of the user ...and on clearing the cache entry you run through all sessions tied to records and perform a batch sql to reset those values in the db...
Just some thoughts as you have multiple scenarios - not only in the ajax enviroment - to consider...
Thanks for all the suggestions Jody. I am most interested in the asynchpostback on the unload event. Seems that this would be the best way to go. Where is the migration guide?
Wednesday, March 21, 2012
Ajax and GridView Sorting or paging
Hello,
I have a main page , it's contain a call page with gridview (with features sorting and paging)
But when I click on link PAGE1, and I click on sorting, It's my page'myPageGridview.aspx' that load.
My aspx page
<head>
<title>Untitled Page</title>
<scriptlanguage=JavaScriptsrc="JavaScript/Ajax.js"></script>
</head>
<body>
<Aclass=parchemin_suite_linkonclick=javascript:show_entry('myPageGridview.aspx');href="#">Page 1</A>
<DIVid=parchemin_zonestyle="DISPLAY: none; LEFT: 102px; POSITION: absolute; TOP: 44px">
<Aonclick=javascript:hide_entry();href="#">Hidden page</A><DIVid=parchemin></DIV>
</DIV>
</body>
</html>
My Javascript page :
var ajax=false;
try
{
// All
ajax =new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try {
// IE
var MSXML_XMLHTTP_PROGIDS =new Array(
'MSXML2.XMLHTTP.5.0',
'MSXML2.XMLHTTP.4.0',
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'
);
for (var i=0; i < MSXML_XMLHTTP_PROGIDS.length ; i++) {
try {
ajax =new ActiveXObject(MSXML_XMLHTTP_PROGIDS[i]);
//alert(MSXML_XMLHTTP_PROGIDS[i]);
}
catch (e)
{
ajax =false;
}
}
}
catch (E) {
ajax =false;
}
}
// Mozilla / Safari
if (!ajax &&typeof(XMLHttpRequest)!='undefined') {
ajax =new XMLHttpRequest();
}
function getMyHTML(serverPage, objID) {
ajax.open("GET", serverPage);
ajax.onreadystatechange =function() {
//alert("Status : " + ajax.status);
if (ajax.readyState == 4 && ajax.status == 200) {
document.getElementById(objID).innerHTML = ajax.responseText;
document.getElementById('parchemin_zone').style.display='';
}
}
ajax.send(null);
}
function show_entry(entry_id)
{
getMyHTML(entry_id,'parchemin');
}
function hide_entry()
{
document.getElementById('parchemin_zone').style.display='none';
}
function view_entry()
{
document.getElementById('parchemin_zone').style.display='inline';
}
function ismaxlength(obj){
var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) :""
if (obj.getAttribute && obj.value.length > mlength)
obj.value = obj.value.substring(0, mlength)
}
nobody has idea ?
when I use an Autopostback, I have this error.
For exemple, I have a main page width 3 page include in Ajax.
when I use autopostback, my page reload width only my table.
Instead of using Ajax I would recommend that you use Atlas. What's the difference? Well Atlas is based on Ajax, at least the idea of Ajax anyway, but it does all the hard work for you. If you download the December release of Atlas (http://www.asp.net/default.aspx?tabindex=7&tabid=47) and visit this blog (http://www.nikhilk.net/AtlasM1.aspx) you will see how easy it is to use. It will virtually eliminate any XML or JavaScript that you have to write. But to answer you question directly. I have no idea what could be wrong with your code. I think that your question would be best served on an Ajax specific forum.
Good luck.
Ajax and GridView Control
I have to Update Panels in my application and i want to make everything work with the code not with the GUI. So when i click insert button it should insert the data from the textboxes to the database and in UpdatePanel2 i want GridView to be automaticly updated. It inserts the data but does not update the GridView , so here is the C# code that i wrote for it
1protected void Page_Load(object sender, EventArgs e)2 {3if (!Page.IsPostBack)4 {5 dataGetir();6 }7else8 {9 dataGetir();10 }1112 }1314protected void dataGetir()15 {16 SqlConnection conn =new SqlConnection("Server=localhost;Database=Calisma;Trusted_Connection=True;");17 SqlCommand cmd =new SqlCommand("Select * From Calisanlar", conn);18 SqlDataAdapter da =new SqlDataAdapter(cmd);1920 DataSet ds =new DataSet();21 da.Fill(ds);22 GridView1.DataSource = ds;23 GridView1.DataBind();24 }25protected void btnInsert_Click(object sender, EventArgs e)26 {27 SqlConnection conn =new SqlConnection("Server=localhost;Database=Calisma;Trusted_Connection=True;");28 SqlCommand cmd =new SqlCommand("insert into Calisanlar(FirstName, LastName) Values(@dotnet.itags.org.First, @dotnet.itags.org.Last)", conn);29 SqlParameter prmFirst =new SqlParameter("@dotnet.itags.org.First", SqlDbType.NVarChar, 50);30 prmFirst.Value = txtIsim.Text;31 SqlParameter prmLast =new SqlParameter("@dotnet.itags.org.Last", SqlDbType.NVarChar, 50);32 prmLast.Value = txtSoyad.Text;3334 cmd.Parameters.Add(prmFirst);35 cmd.Parameters.Add(prmLast);3637 conn.Open();38 cmd.ExecuteNonQuery();39 txtIsim.Text = String.Empty;40 txtSoyad.Text = String.Empty;41 conn.Close();4243 }44protected void btnCancel_Click(object sender, EventArgs e)45 {46 txtIsim.Text = String.Empty;47 txtSoyad.Text = String.Empty;48 }
And here is the source code that i wrote for the panels
1<form id="form1" runat="server">2 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />3 <div>4 <asp:UpdatePanel ID="UpdatePanel1" runat="server" >5 <ContentTemplate>6 <table style="width: 200px; border-width: 0px; background-color:Blue;">7 <tr>8 <td style="width: 4px">9 <asp:Label ID="Label1" runat="server" Text="?sim"></asp:Label></td>10 <td>11 <asp:TextBox ID="txtIsim" runat="server"></asp:TextBox></td>12 </tr>13 <tr>14 <td style="width: 4px">15 <asp:Label ID="Label2" runat="server" Text="Soyad"></asp:Label></td>16 <td>17 <asp:TextBox ID="txtSoyad" runat="server"></asp:TextBox></td>18 </tr>19 <tr>20 <td style="width: 4px">2122 </td>23 <td>24 <table style="width: 150px; border-width: 0; background-color: Blue;">25 <tr>26 <td style="width: 33px; height: 26px">27 <asp:Button ID="btnInsert" runat="server" Text="Insert" OnClick="btnInsert_Click" /></td>28 <td style="height: 26px">29 <asp:Button ID="btnICancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" /></td>30 </tr>31 </table>32 </td>33 </tr>34 </table>35 </ContentTemplate>36 </asp:UpdatePanel>37 <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">38 <ContentTemplate>39 <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">40 <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />41 <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />42 <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />43 <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />44 <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />45 <AlternatingRowStyle BackColor="White" />46 </asp:GridView>47 </ContentTemplate>48 <Triggers>49 <asp:AsyncPostBackTrigger ControlID="btnEkle" EventName="Click" />50 </Triggers>51 </asp:UpdatePanel>5253 </div>54 </form>So i am so confused about Ajax, thanks for your helps
You need to open the connection to your database for it to send the query. One way to check this is by using the Sql Profiler inside of the SQL Server Management Studio under the Tools menu. That could help you diagnose in the future a problem like this.
To fix modify you code like so:
16 SqlConnection conn =new SqlConnection("Server=localhost;Database=Calisma;Trusted_Connection=True;");
17 SqlCommand cmd =new SqlCommand("Select * From Calisanlar", conn);
18 SqlDataAdapter da =new SqlDataAdapter(cmd);
19
20 DataSet ds =new DataSet();
21 conn.Open();
22 da.Fill(ds);
23 conn.Close();
24 GridView1.DataSource = ds;
25 GridView1.DataBind();
Also in your Page_Load routine you shouldn't really call the binding sub routine in both conditions. You really don't need the IF statement because it runs everytime no matter what.
It should look like this:
3 if (!Page.IsPostBack)
4 {
5 dataGetir();
6 }
7 else
8 {
9 //Nothing here
10 }
Let me know how that works.
JoeWeb
I modified the lines like you said. But it didn't work i mean it inserts the data into database but it doesn't refresh the GridView. When i refresh the whole page then the GridView refreshes too. I guess there is something wrong with the source code. Because normally the code that i wrote insterts the data and selects the data no problem. The problem is in the Update Panel i guess?
Mehmet Serif
You are doing an AsyncTrigger... with this control btnEkle
I don't see you referencing that control anywhere in the frontend code. You need to put that button inside the updatepanel enclosing the gridview for the updatepanel to be triggered for an update. Otherwise just remove the asynctrigger and it will update the panel nonetheless.
JoeWeb
btnEkle is already referenced in UpdatePanel2 as an AsyncTrigger control with its Click event..and btnEkle button is in UpdatePanel1 and should trigger the UpdatePanel2..if you say it's not referenced to anywhere then how can i reference it?
Thanks
I think what he's saying is that in the code you pasted in this thread, there's no button called btnEkle.
oh yes you are right but in its original code there is no btnInsert instead there is a btnEkle so no problem about the buttons..
Would you mind pasting the actual code you're using (since this apparently wasn't it)?
My best guess without being able to see the code is that you need to call DataBind() on your DataGrid in your click event handler.
ughnn i forgot to call dataGetir() function in Click event of btnEkle button. Thanks for the help..