Click here to Skip to main content
15,886,110 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Generalsilly :| Pin
Spykraft22-Jan-08 5:07
Spykraft22-Jan-08 5:07 
GeneralRe: silly :| Pin
ToddHileHoffer22-Jan-08 6:24
ToddHileHoffer22-Jan-08 6:24 
GeneralRe: silly :| Pin
Declan Bright22-Jan-08 6:43
Declan Bright22-Jan-08 6:43 
QuestionLimiting input in textbox Pin
Ni Na22-Jan-08 2:46
Ni Na22-Jan-08 2:46 
GeneralRe: Limiting input in textbox Pin
eyeseetee22-Jan-08 5:15
eyeseetee22-Jan-08 5:15 
GeneralRe: Limiting input in textbox Pin
ice-hotty22-Jan-08 18:36
ice-hotty22-Jan-08 18:36 
GeneralReverse DNS in .NET Pin
Waleed Eissa22-Jan-08 1:43
Waleed Eissa22-Jan-08 1:43 
GeneralThe responseText property of XMLHttpRequest object is returning the whole HTML page Pin
AumSingh22-Jan-08 1:42
professionalAumSingh22-Jan-08 1:42 
Hello all,

I am a newbie to the AJAX programming techniques. I want to update my database as per choice made by the user and inform him/her about the same if the updation has been done successfully. The platform is ASP.NET

Following is my implementation:

The file containing following two javascript functions has been included in my ASPX file.

This function (i.e. submitValue) is called on the button click and the parameter (i.e. value) is the data I want to update on my database. The function "getXmlHttp()" in bold is returning the required XMLHttpRequest object by using the suitable method as per the browser detected. As I want to inform the user on the same page so the variable "requestURL" passed in the open() function contains the URL of the same page with updated querystring.

function submitValue(value)
{
try
{
//Create the XMLHttpRequest object.
xmlHttp = getXmlHttp();


//Call the function to process the response from the server
xmlHttp.onreadystatechange = stateChanged;

//Send request to the server
var requestURL = location.href+"&q="+value;

xmlHttp.open('GET',requestURL,true);
xmlHttp.send(null);

}
catch(e)
{
alert("Error : Sending request");
}
}

Following javascript function which is called above is used to process the server response.

function stateChanged()
{
try
{
if (xmlHttp.readyState==4 ||xmlHttp.readyState=='complete')
{
var retValue;
retValue = xmlHttp.responseText;

if(retValue=="0")
document.getElementById("divRateInfo").innerHTML = "Rating submition failed. Try again.";

else

document.getElementById("divRateInfo").innerHTML = "Rating successfully submited!";

}
}
catch(e)
{
alert("Error : Processing response");
}
}


Finally following is the code behind written on the corresponding ASPX.CS file. The method is called on the page load.


private void SaveRating()
{
try
{
if (Request.QueryString["q"] != null)
{
int nUserRate = Convert.ToInt32(Request.QueryString["q"].ToString());

SqlParameter[] sqlParam = new SqlParameter[2];
sqlParam[0] = new SqlParameter("@rate", SqlDbType.Int);
sqlParam[0].Value = nUserRate;
sqlParam[1] = new SqlParameter("@id", SqlDbType.Int);
sqlParam[1].Value = Convert.ToInt32(this.Request.QueryString["id"].ToString());
object strInfo = SqlHelper.ExecuteScalar(ConfigurationSettings.AppSettings["ConnectionString"], CommandType.StoredProcedure, "sp_UpdateRating", sqlParam);

Response.Expires = -1;
Response.Write(strInfo.ToString());
}
}
catch (Exception objExcep)
{
Response.Expires = -1;
Response.Write("0");
}
}

Everything works as per expectation, even my database is getting updated perfectly but the "responseText" property in the function "stateChanged()" above is returning the code for my ASPX page instead of just 0 or 1 as expected.

O my god the post has become so long but I wanted to make myself clear. Can anyone suggest any solution? Please help!
GeneralRe: The responseText property of XMLHttpRequest object is returning the whole HTML page Pin
sulabh202022-Jan-08 18:23
sulabh202022-Jan-08 18:23 
QuestionRecord No in Cross-Tab Pin
Pankaj Garg22-Jan-08 1:20
Pankaj Garg22-Jan-08 1:20 
Questionhow can i maintain a session on client side ? Pin
manish.singhal22-Jan-08 1:00
manish.singhal22-Jan-08 1:00 
AnswerRe: how can i maintain a session on client side ? Pin
J4amieC22-Jan-08 1:11
J4amieC22-Jan-08 1:11 
GeneralRe: how can i maintain a session on client side ? Pin
manish.singhal5-Feb-08 22:28
manish.singhal5-Feb-08 22:28 
Generalliteral not displaying html tags Pin
samerh22-Jan-08 0:46
samerh22-Jan-08 0:46 
GeneralRe: literal not displaying html tags Pin
Paddy Boyd22-Jan-08 2:17
Paddy Boyd22-Jan-08 2:17 
AnswerRe: literal not displaying html tags Pin
Guffa22-Jan-08 2:48
Guffa22-Jan-08 2:48 
GeneralRe: literal not displaying html tags Pin
samerh22-Jan-08 3:55
samerh22-Jan-08 3:55 
Generalreceiving email in asp.net application Pin
krishnaveer21-Jan-08 23:50
krishnaveer21-Jan-08 23:50 
QuestionDisplay first (n) number of words of string...... Pin
munklefish21-Jan-08 23:40
munklefish21-Jan-08 23:40 
GeneralRe: Display first (n) number of words of string...... Pin
sulabh202022-Jan-08 1:29
sulabh202022-Jan-08 1:29 
GeneralRe: Display first (n) number of words of string...... Pin
munklefish22-Jan-08 1:50
munklefish22-Jan-08 1:50 
AnswerRe: Display first (n) number of words of string...... Pin
Guffa22-Jan-08 2:54
Guffa22-Jan-08 2:54 
Generalmethod call after link click Pin
gottimukkala21-Jan-08 23:36
gottimukkala21-Jan-08 23:36 
GeneralRe: method call after link click Pin
Paddy Boyd22-Jan-08 0:18
Paddy Boyd22-Jan-08 0:18 
GeneralRe: method call after link click Pin
gottimukkala22-Jan-08 1:08
gottimukkala22-Jan-08 1:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.