Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Wednesday, March 28, 2012

Why to use asp.net ajax

Anthem.net is so simple to use on doesnot even have to write a line of code.

Why should we consider using msft asp.net ajax instead of anthem.net ?

thanks

Because ASP.NET Ajax is part of the .Net framework, so you are assured of support, documentation and continued development (and a huge and growing amount of tutorials etc from users). That can never be said of Anthem.Net. What happens if the creator just gets bored with it one day?


do we have to write lines of javascript code with asp.net ajax version?

Thanks for your help


No you don't have to. You can use its basic functionality without writing one line of code. You can also use all the extenders in the control toolkit without writing any javascript. However, you can also customise the behaviours as much as you want by adding some javascript. Watch some of theAjax videos here

Monday, March 26, 2012

Window.alert

Hello,

I'm trying

Response.Write(

"<script>window.alert('Impossible de supprimer cette action, cette action à déjà été effectuée ou elle doit être utilisée ...');</script>")

And i'have the Windows Internet explorer "Sys.WebForms.PageRequestManagerParserException: 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 '<script>window.alert'.

Do you have an idea ? Thanks alain

Hey,

Yes, AJAX doesn't like the Response object. You could try using Page.ClientScript.RegisterClientScriptBlock() to add the script to the page. An alternative way is that if this event is triggered by a button or something, embed it in the control.


Actually, instead of using Page.ClientScript.Register*, use ScriptManager.Register*. That way the right thing happens during partial rendering.
Thanks both I used now :

ScriptManager.RegisterClientScriptBlock(

Me,Me.GetType(),"ClientScript","window.alert('Vous ne pouvez pas supprimer un client utilisez le champ Statut');",True)

and it run fine.

Big Smile Alain

Wednesday, March 21, 2012

Write to database using AJAX

Hello, everyone. I'm trying to finish up a project where users store information into our sales database. It would be immensely helpful to be able to insert this data (or update the data) without refreshing the page, which I can only imagine would use AJAX. Unfortunately, I'm having a hard time finding the proper information on how to do this. Is there a handy little AJAX control that helps with this? Is it something I'll have to write myself? Any hints, suggestions and/or pointings in the right direction would be greatly appreciated.

not sure on what you have, but you do have several options:

1. use web services to do that. you'd call them through your page by using js proxies that can be automatically inserted on the page.

2. use an updatepanel to wrap parts of the page that should be refreshed.


Luis Abreu:

1. use web services to do that. you'd call them through your page by using js proxies that can be automatically inserted on the page.

This is precisely what I'm going to try to use. Seems cleaner to me and I think I understand it better than the updatepanel. Thanks for the information! I really appreciate it.


hello again.

yes, if you ask me, the correct way of using ajax it to use web services to get the data and then js to update the dom presented by the browser. anyway, you cannot deny that the UpdatePanel has some cool things and it'll work nicely in several scenarios.

Write Xml/Script in Server Side

Hi,

Is there any way to write the Xml/Script other than using the XmlWriter. I mean is there any sever side object model of atlas, which I can utilize to generate these scripts. Can you guys please give an estimated time when the complete documentation is publicly available?

You can write XML Script in one of two ways:

- You can just have static XML-script directly on the ASP.NET page. The script can use ASP.NET databinding expressions, and even repeaters.

- You can use the Atlas ScriptManager control, which provides an object model to help you generate scripts from ASP.NET server controls. For a couple of examples, check out Nikhil's blog post:

http://www.nikhilk.net/AtlasScriptManager.aspx

- If you have a control or extender that needs to write script, you can register with the ScriptManager by calling RegisterControl, and implement the RenderScript method. For an example, see:

http://www.nikhilk.net/AtlasInPlaceEditSampleBehavior.aspx

Write Xml/Script in Server Side

Hi,

Is there any way to wite the Xml/Script other than the XmlWriter. I mean is there any sever side objet model of atlas which I can utilize to generate these scripts.

You could create your own custom ATLAS control implementing the RenderScript method of the IScriptControl interface. For instance the following implementation:

public void RenderScript(ScriptTextWriter writer)
{
//Outputs <control> tag
GenericScriptComponent gsc = new GenericScriptComponent(new ScriptTypeDescriptor("control", ScriptNamespace.Default));
//Outputs <behaviors> tag
gsc.ID = this.ClientID;
GenericScriptComponent draggableBehavior = new GenericScriptComponent(new ScriptTypeDescriptor("draggableListItem", ScriptNamespace.Default));
draggableBehavior.AddValueProperty("handle", this.ClientID);
gsc.AddCollectionItem("behaviors", draggableBehavior);
((IScriptObject)gsc).RenderScript(writer);
}

will output the following XML-Script:

<control id="webPart1">
<behaviors>
<draggableListItem handle="webPart1Title" />
</behaviors>
</control>

xmlHttp with responseXML

I'm trying to write a script page that uses the xmlHTTP to an aspx page that then sends back some XML which I can then use the javascript to read and populate a dropdown list.

I seem to be running into the problem of the returned XML (or lack there of) If I do a responseText, all is well cept the response is not formatted as XML just a large string.

Here is the Javascript

1<script type="text/javascript">2 /* Create a new XMLHttpRequest object to talk to the Web server */3 var xmlHttp = false;45 function CreateXmlHttp()6 {7 /*@dotnet.itags.org.cc_on @dotnet.itags.org.*/8 /*@dotnet.itags.org.if (@dotnet.itags.org._jscript_version >= 5)910 try11 {12 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");13 } catch (e)14 {15 try16 {17 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");18 }19 catch (e2)20 {21 xmlHttp = false;22 }23 }24 @dotnet.itags.org.end @dotnet.itags.org.*/2526 if (!xmlHttp && typeof XMLHttpRequest != 'undefined')27 {28 xmlHttp = new XMLHttpRequest();29 }30 }313233 function callServ()34 {3536 var site;37 var siteddl = document.getElementById('ddlSites');38 for (var i = 0; i < siteddl.options.length; i++)39 {40 if (siteddl.options[i].selected)41 {42 site = siteddl.options[i].value;43 //document.write(site);44 }45 }46 if (site == '-1')47 {48 return;49 }50 else51 {5253 CreateXmlHttp();5455 var url="popddls.aspx?w=1&id=" + escape(site);565758 xmlHttp.open("GET", url, true);5960 xmlHttp.setRequestHeader("Content-Type", "text/xml");6162 xmlHttp.onreadystatechange = updatePage;6364 xmlHttp.send(null);65 }6667 }6869 function updatePage()70 {71 if(xmlHttp.readyState ==4)72 {73 var response1 = xmlHttp.responseXML;7475 var ddlGrades = document.getElementById('ddlGrades');7677 var grades = response1.getElementsByTagName("grade");78 //ddlGrades.options.length = 0;79 for (var x=0; x < grades.length; x++)80 {81 var id = grades[x].childNodes[0].value;82 var gradedate = grades[x].childNodes[1].value;83 document.write(id + " " + gradedate);84 var newOption = new option();85 newOption.text = gradedate;86 newOption.valueOf = id;87 ddlGrades.options[ddlGrades.length] = newOption;88 }8990 }91 }929394 </script>

Here is the code for popddl which if I run it, it does write the correct XML

1Sub load_gradesddl()2Dim idAs Integer = Request.QueryString("id")3Dim sqlAs String ="select id,gradedate from grades where siteid=" & id4Dim dsAs System.Data.DataSet = DataFunc.FillDS(sql,"gcioq")56 Response.Write("<?xml version=""1.0"" encoding=""utf-8"" ?>")7 Response.Write("<grades>")8For IAs Integer = 0To ds.Tables(0).Rows.Count - 1910 Response.Write("<grade>")11 Response.Write("<id>" & ds.Tables(0).Rows(I).Item("id") &"</id>")12 Response.Write("<gradedate>" & ds.Tables(0).Rows(I).Item("gradedate") &"</gradedate>")13 Response.Write("</grade>")14Next15 Response.Write("</grades>")16End Sub

the error I get in firefox is response1 has no properties. in IE7 I do not get an error but it doesn't work.

What am I doing wrong here?

EDIT:

I also noticed if I do a document.write(grades.length) I get a Zero back though I know the popddl is generating correct XML.

Ok, I got it to work but only in IE7, in firefox it get the right amound of nodes but everything comes out as undefined.

using this to get the data

var id = grades[x].childNodes[0].firstChild.text;

var gradedate = grades[x].childNodes[1].firstChild.text;

Also, this is the XML output

<?xml version="1.0" encoding="utf-8"?>

-<grades>

-<grade>

<id>11</id>

<gradedate>11/27/2007</gradedate>

</grade>

- <grade>

<id>18</id>

<gradedate>11/27/2006</gradedate>

</grade>

-<grade>

<id>19</id>

<gradedate>11/28/2007</gradedate>

</grade>

-<grade>

<id>20</id>

<gradedate>11/29/2007</gradedate>

</grade>

-<grade>

<id>21</id>

<gradedate>11/30/2007</gradedate>

</grade>

</grades>


Ok, I got it to work but only in IE7, in firefox it get the right amound of nodes but everything comes out as undefined.

using this to get the data

var id = grades[x].childNodes[0].firstChild.text;

var gradedate = grades[x].childNodes[1].firstChild.text;

Also, this is the XML output

<?xml version="1.0" encoding="utf-8"?>

-<grades>

-<grade>

<id>11</id>

<gradedate>11/27/2007</gradedate>

</grade>

- <grade>

<id>18</id>

<gradedate>11/27/2006</gradedate>

</grade>

-<grade>

<id>19</id>

<gradedate>11/28/2007</gradedate>

</grade>

-<grade>

<id>20</id>

<gradedate>11/29/2007</gradedate>

</grade>

-<grade>

<id>21</id>

<gradedate>11/30/2007</gradedate>

</grade>

</grades>


Hi,

Thank you or your post!

I suggest you try this for firefox:

var id = grades[x].childNodes[0].firstChild.nodeValue;

var gradedate = grades[x].childNodes[1].firstChild.nodeValue;

If you have further questions,let me know.

Best Regards,

xmlhttprequest "post"

hi there...

i started to using xmlhttprequest and i able to write few pages using "get"

but wondering how can i do using "post"

i have a data-entry page and i grab all the values and post to db

any sample code?

thanks.

from googling.

top 2 of the search

http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
http://www.devx.com/DevX/Tip/17500


busyweb:

from googling.

top 2 of the search

http://www.openjs.com/articles/ajax_xmlhttp_using_post.php
http://www.devx.com/DevX/Tip/17500


i did google and i have seen the above two links but its not complete and i'm still looking for the part where/how do i put the data into db

what i mean by this below code:

var objHTTP, strResult;
objHTTP = new ActiveXObject('Microsoft.XMLHTTP');
objHTTP.Open('POST',"OtherPage.asp",false);
objHTTP.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');

objHTTP.send("id=1&user="+txtUser.value+"&password="+txtPassword.value);

strResult=objHTTP.responseText;<<<< after you havestrResult do you split the data ?


If you're using the asp.net ajax framework (as posting on this forum would indicate), then by far your easiest method is to use the Sys.Net.WebRequest javascript method that you can find inhttp://ajax.asp.net/docs

paul.vencill:

If you're using the asp.net ajax framework (as posting on this forum would indicate), then by far your easiest method is to use the Sys.Net.WebRequest javascript method that you can find inhttp://ajax.asp.net/docs


paul.vencill:

If you're using the asp.net ajax framework (as posting on this forum would indicate), then by far your easiest method is to use the Sys.Net.WebRequest javascript method that you can find inhttp://ajax.asp.net/docs


paul.vencill:

If you're using the asp.net ajax framework (as posting on this forum would indicate), then by far your easiest method is to use the Sys.Net.WebRequest javascript method that you can find inhttp://ajax.asp.net/docs

i'm usingxmlhttprequest


Yeah, that's the object; I'm talking about the .js library / framework... Sys.Net.WebRequest fires an XmlHttpRequest under the hood, it just abstracts the interface for you to make it easier (like most ajax frameworks do)...


paul.vencill:

Yeah, that's the object; I'm talking about the .js library / framework... Sys.Net.WebRequest fires an XmlHttpRequest under the hood, it just abstracts the interface for you to make it easier (like most ajax frameworks do)...

i dont know if we are on same page

my questions is pretty simple..

i just need an example: how to insert data into db usingxmlhttprequest.

thanks.


Hello,

I'm from Earth too..

Really, good to see you here.

I think that you don't add data with result from server at the client side (web browser).

But you have(might, may be not) to utilize the data posted with xmlhttprequest at the SERVER.

This is the way of EARTH People doing, just joke!!!


Unless you're talking about something I'm not familiar with, XmlHttpRequest is an object that is exposed by modern browsers which allows you to communicate with the server without doing a full page postback. The AsP.Net ajax extensions Javascript object called Sys.Net.WebRequest is a wrapper around the XmlHttpRequest object which allows you to access it without necessarily knowing all the gory details.

As the other poster said, you don't insert data into a database using XmlHttpRequest, typically, what you do is make a request to your web server using XmlHttpRequest, and then the web server resource that you called w/ the XmlHttpRequest object parses that request and does 'something' with it, potentially inserting a record in the database. There's loads of examples of this under the docs of this site. http://ajax.asp.net/docs