Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Undefines 3

Status
Not open for further replies.

kurie

Programmer
Jun 4, 2008
170
ZA
Does anyone see what im doing wrong here, i get the value undefined if i try to reference the query string;
strUserName = Convert.ToString(Session["Username"]);

Please note that lblUserName is a label, it seem to work only when i use a textbox

function QuestionOpenWindow(strIndex)
{
var strUsername = document.getElementById('<%=lblUserName.ClientID%>').value;
MyWindow1 = window.open("frmQuestionType.aspx?ID=" + strIndex + "&strUsername=" + strUsername ,"", "location=0,status=0,scrollbars=0,width=600,height=500");
MyWindow1.moveTo(320,150);
}
 
I don't really know what you are doing (and I may be confused because I don't know aspx)... but here goes!

I think you are trying to access the GET parameter called Username serverside... but you are passing through the GET parameter strUsername in your javascript:
Code:
function QuestionOpenWindow(strIndex) {
  var strUsername = document.getElementById('<%=lblUserName.ClientID%>').value;
  MyWindow1 = window.open("frmQuestionType.aspx?ID=" + strIndex + "&[!]strUsername[/!]=" + strUsername, "", "location=0, status=0, scrollbars=0, width=600, height=500");
  MyWindow1.moveTo(320,150);
}
If I'm right, then it's as simple as changing either the server-side or the client-side code to use the same GET parameter.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Nice guess, those are the ones very difficult to catch.

Appart from than, and assuming you're getting the error at server side, I think you're not retrieving the queryString but the session variables. Maybe you'd need to use Request.queryString[strUserName] but this is more an aspx question.

Cheers,
Dian
 
im sorry about that, if i use sessions it works fine and the code i posted,strUserName = Convert.ToString(Session["Username"]);, is for the session but i dont want to use the session, here is the line that is giving the problem
strUserName = Convert.ToString(Request.QueryString["strUsername"]);
is it possible to reference a value from a label in javascript. like this
var strUsername =document.getElementById('<%label1.ClientID%>').value;


 
The answer is yes. Whatever <%label1.ClientID%> renders to should be a valid ID on the input you want to get the value from... that way your javascript will work.

I'm not sure if you are aware of this (so I'll state it for the record)...

You cannot access client-side variables from the server-side (you cannot use PHP to access data on the rendered page). You can use PHP to assist in building up javascript on the client-page... but once the page has been delivered to the browser, PHP has no control/access to the page.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top