On the MemberDetails.aspx page I am trying to use GridView that will show just the details for the user in the link (i.e. James)
On the client side I have some java script to pick off the user name (and some other info perhaps later)
window.onload = getUserName;
function getUserName(){
var query = location.search.substring(1);
// split the rest at each "&" character to give a list of "argname=value" pairs
var pairs = query.split("&");
for (var i=0; i<pairs.length; i++) {
// break each pair at the first "=" to obtain the argname and value
var pos = pairs[i].indexOf("=");
var argname = pairs[i].substring(0,pos);//.toLowerCase();
var value = pairs[i].substring(pos+1);
// process each possible argname
if (argname ==
"UserName") {UserName = parseFloat(value);}
Protected Sub Page_Load(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles Me.Load
Member.Text = HiddenControl1.Value.ToString()
End Sub
The SQL data source I am using has:
WHERE (Details.UserName = @UserName)
with the control specified as:
<asp:ControlParameter
ControlID="Member"
Name="UserName"
PropertyName="Text"
/>
When the MemberDetails.aspx page is loaded as MemberDetails.aspx?UserName=James then the label
<asp:Label
ID="Member"
runat="server"
Font-Names="Arial"></asp:Label>
shows up on the loaded page as James. However, the Text property is not set to James. (I checked this with another label id "check" with server script check.Text = HiddenControl1.Value.ToString() this did not appear on the loaded web page)
I am not sure I have understood how the text property is being set. Could someone please help with an explanation and a possible solution.
Thats wrong. When your set the innerHtml, its the value between the html tags you set. Example. <asp:Label ID="member">This Is InnerHtml Text<asp:Label />
Then in the Load of the page MemberDetails you do this:
Dim userName as String = Request.Params("UserName")
Then the string userName will be James, and then on the page MemberDetails you can use that variable to filter the gridview
Hope this helps!
Wim
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Marked as answer by sharpeeuk on Mar 18, 2007 01:43 PM
The Text property is a server-side only property. Client-side (getElementById('<%= yourLabel.ClientID %>')) you have to use either innerHTML or innerText, but one works with all browsers and one only works with IE (I forget which).
BTW, your problem might be that you're using an incorrect ID for the element, if the element is inside of a second container. The example above will work with all possibilities.
NC...
Marked as answer by sharpeeuk on Mar 19, 2007 08:05 PM
sharpeeuk
Member
20 Points
62 Posts
Text property of a Label from getElementbyID
Mar 18, 2007 10:59 AM|LINK
Hello,
I am trying to pass a user name from one page to another using JavaScript. The page link created is like:
http://localhost:4614/Webpage/MemberDetails.aspx?UserName=James
On the MemberDetails.aspx page I am trying to use GridView that will show just the details for the user in the link (i.e. James)
On the client side I have some java script to pick off the user name (and some other info perhaps later)
window.onload = getUserName;
function getUserName(){ var query = location.search.substring(1);
// split the rest at each "&" character to give a list of "argname=value" pairs var pairs = query.split("&"); for (var i=0; i<pairs.length; i++) { // break each pair at the first "=" to obtain the argname and value var pos = pairs[i].indexOf("="); var argname = pairs[i].substring(0,pos);//.toLowerCase(); var value = pairs[i].substring(pos+1); // process each possible argname if (argname == "UserName") {UserName = parseFloat(value);}}
document.getElementById(
"Member").innerHTML = value.toString();document.getElementById(
"HiddenControl1").value = value.toString();}
With<
asp:Label ID="Member" runat="server" Font-Names="Arial"></asp:Label><
input type="hidden" ID="HiddenControl1" name="yourHiddenControl1" runat="server">One the server side I have:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadMember.Text = HiddenControl1.Value.ToString()
End Sub The SQL data source I am using has: WHERE (Details.UserName = @UserName)with the control specified as: <asp:ControlParameter ControlID="Member" Name="UserName" PropertyName="Text" />
When the MemberDetails.aspx page is loaded as MemberDetails.aspx?UserName=James then the label <asp:Label ID="Member" runat="server" Font-Names="Arial"></asp:Label> shows up on the loaded page as James. However, the Text property is not set to James. (I checked this with another label id "check" with server script check.Text = HiddenControl1.Value.ToString() this did not appear on the loaded web page)
I am not sure I have understood how the text property is being set. Could someone please help with an explanation and a possible solution.
Many thanks
deblendewim
Contributor
5590 Points
951 Posts
Re: Text property of a Label from getElementbyID
Mar 18, 2007 12:32 PM|LINK
Hi Sharpeeuk,
Where you do this in the javascript:
document.getElementById("Member").innerHTML = value.toString();
Thats wrong. When your set the innerHtml, its the value between the html tags you set. Example. <asp:Label ID="member">This Is InnerHtml Text<asp:Label />
What you need to do is this i think:
document.getElementById("Member").Text = value.toString();
Maybe a better way to get the username on the page with the gridview (MemberDetails.aspx) is like this:
You open the page with an url parameter like this: http://localhost:4614/Webpage/MemberDetails.aspx?UserName=James
Then in the Load of the page MemberDetails you do this:
Dim userName as String = Request.Params("UserName")Then the string userName will be James, and then on the page MemberDetails you can use that variable to filter the gridview
Hope this helps!
Wim
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: Text property of a Label from getElementbyID
Mar 18, 2007 03:44 PM|LINK
The Text property is a server-side only property. Client-side (getElementById('<%= yourLabel.ClientID %>')) you have to use either innerHTML or innerText, but one works with all browsers and one only works with IE (I forget which).
BTW, your problem might be that you're using an incorrect ID for the element, if the element is inside of a second container. The example above will work with all possibilities.
NC...
sharpeeuk
Member
20 Points
62 Posts
Re: Text property of a Label from getElementbyID
Mar 19, 2007 08:04 PM|LINK
Thanks
In the end I used:
Dim userName as String = Request.Params("UserName")
Member.Text = userName.ToString
Not sure if this is best, but it worked fine.
Thanks again to both for the great help