i am using the following code to get LogedInUser
from LogIn.aspx
and send it to Chat.aspx
then send it to FrmForAjaxCalls
to return data from Db and fill it on div but in running time it telling me in browser console request.querystring is undefined
here is LogIn.aspx
code
protected void Button3_Click(object sender, EventArgs e)
{
Response.Redirect("Chat.aspx?LGN2="+TextBoxUserName.Text);
}
and this is Chat.aspx
javascript code
<script type="text/javascript" >
var xmlhttp;
function GetData() {
xmlhttp = null;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject();
}
string LogedInUser = Request.Cookies["LogedInUser"].Value;
var LogedInUser = Request.QueryString["LGN2"];
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readystate == 4 || xmlhttp.status == 200) {
document.getElementById("MyDiv").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "FrmForAjaxCalls.aspx?LGN=" + LogedInUser, true);
xmlhttp.send();
}
then i send it to FrmForAjaxCalls
to return data but its return nothing on the div with Request.QueryString
is undefined exption on browser console
protected void Page_Load(object sender, EventArgs e)
{
string LogedInUser = Request.QueryString["LGN2"].ToString();
StringBuilder html = new StringBuilder();
String result = String.Empty;
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["CRConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand("Select MessageNum , Message , SenderName ,Date from Message where ReciverUserName='" + LogedInUser + "'", cnn);
cnn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
html.Append("<div id = xxx> ");
html.Append("<table border='1'>");
html.Append("<tr>");
foreach (DataColumn col in dt.Columns)
{
html.Append("<th>");
html.Append(col.ColumnName);
html.Append("</th>");
}
html.Append("</tr>");
foreach (DataRow row in dt.Rows)
{
html.Append("<tr>");
foreach (DataColumn col in dt.Columns)
{
html.Append("<td>");
html.Append(row[col.ColumnName]);
html.Append("</td>");
}
html.Append("</tr>");
}
html.Append("</table>");
html.Append("</div>");
Response.Write(html);
}
In your paste for Chat.aspx
, you're calling it LGN
instead of LGN2
... Could that be all? In situations like this, your first mission should be to add logging throughout the process to see where it falls apart, so you can pinpoint where the problem is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.