Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > document.getElementById(), error in content page content page

Reply
Thread Tools

document.getElementById(), error in content page content page

 
 
Dave L
Guest
Posts: n/a
 
      03-04-2010
Could someone explain: I have a java popup window function that I would
like to pass a querystring ID from a hiddenfield on my asp.net content page.
The following code works. Note: for this test I simply set the hiddefield
var TransID.value = 21 in btnPopUp.click event See Item 1. The thing I
don't understand is why can't I have the function take the TransID as a
parameter. see Item 2.


**************Item 1.****************

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" >
function PopUp() {

var InqID = document.getElementById('<%=TransID.ClientID%>').v alue;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascriptopUp();" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>



*************Item 2.****************

This Fails

***********************************


<script type="text/javascript" >
function PopUp(obj) {

var InqID = document.getElementById(obj).value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascriptopUp('<%=TransID.Client ID%>');" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>


Any help would be greatly appreaciated.

Feel free to email me at

 
Reply With Quote
 
 
 
 
Mr. Arnold
Guest
Posts: n/a
 
      03-04-2010
Dave L wrote:
> Could someone explain: I have a java popup window function that I would
> like to pass a querystring ID from a hiddenfield on my asp.net content
> page. The following code works. Note: for this test I simply set the
> hiddefield var TransID.value = 21 in btnPopUp.click event See Item 1.
> The thing I don't understand is why can't I have the function take the
> TransID as a parameter. see Item 2.
>
>


<script type="text/javascript" >
function PopUp(obj) {

var InqID = document.getElementById(obj).value;
alert(InqID);
}

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:Button ID="btnPopUp" runat="server" Text="Press Me"
OnClientClick="javascriptopUp('<%=TransID.Client ID%>');" />

<asp:HiddenField ID="TransID" runat="server" />
</asp:Content>
------------------------------------------------

Didn't you pass the control as an object to the function?

Maybe, I am wrong, but the object has the data and you don't need to do
getEbyID in the function, because you passed the control to the function.

var InqID = object.value;

But first do an alert(obj) to even see if you have an object.
 
Reply With Quote
 
 
 
 
Göran Andersson
Guest
Posts: n/a
 
      03-04-2010
Mr. Arnold wrote:
> Dave L wrote:
>> Could someone explain: I have a java popup window function that I
>> would like to pass a querystring ID from a hiddenfield on my asp.net
>> content page. The following code works. Note: for this test I simply
>> set the hiddefield var TransID.value = 21 in btnPopUp.click event See
>> Item 1. The thing I don't understand is why can't I have the function
>> take the TransID as a parameter. see Item 2.
>>
>>

>
> <script type="text/javascript" >
> function PopUp(obj) {
>
> var InqID = document.getElementById(obj).value;
> alert(InqID);
> }
>
> </script>
> </asp:Content>
> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
> Runat="Server">
> <asp:Button ID="btnPopUp" runat="server" Text="Press Me"
> OnClientClick="javascriptopUp('<%=TransID.Client ID%>');" />
>
> <asp:HiddenField ID="TransID" runat="server" />
> </asp:Content>
> ------------------------------------------------
>
> Didn't you pass the control as an object to the function?
>
> Maybe, I am wrong, but the object has the data and you don't need to do
> getEbyID in the function, because you passed the control to the function.
>
> var InqID = object.value;
>
> But first do an alert(obj) to even see if you have an object.


No, it's not an object, it's a string. Note the apostrophes around the
value in the function call.

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
Göran Andersson
Guest
Posts: n/a
 
      03-04-2010
Dave L wrote:
> Could someone explain: I have a java popup window function that I would
> like to pass a querystring ID from a hiddenfield on my asp.net content
> page. The following code works. Note: for this test I simply set the
> hiddefield var TransID.value = 21 in btnPopUp.click event See Item 1.
> The thing I don't understand is why can't I have the function take the
> TransID as a parameter. see Item 2.
>
>
> **************Item 1.****************
>
> <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
>
> <script type="text/javascript" >
> function PopUp() {
>
> var InqID = document.getElementById('<%=TransID.ClientID%>').v alue;
> alert(InqID);
> }
>
> </script>
> </asp:Content>
> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
> Runat="Server">
> <asp:Button ID="btnPopUp" runat="server" Text="Press Me"
> OnClientClick="javascriptopUp();" />
>
> <asp:HiddenField ID="TransID" runat="server" />
> </asp:Content>
>
>
>
> *************Item 2.****************
>
> This Fails
>
> ***********************************
>
>
> <script type="text/javascript" >
> function PopUp(obj) {
>
> var InqID = document.getElementById(obj).value;
> alert(InqID);
> }
>
> </script>
> </asp:Content>
> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
> Runat="Server">
> <asp:Button ID="btnPopUp" runat="server" Text="Press Me"
> OnClientClick="javascriptopUp('<%=TransID.Client ID%>');" />
>
> <asp:HiddenField ID="TransID" runat="server" />
> </asp:Content>
>
>
> Any help would be greatly appreaciated.
>
> Feel free to email me at


The problem is that you can't have a script tag inside the Button tag.

The easiest is to set the OnClientClick value from code behind:

btnPopUp.OnClientClick = "PopUp('" + TransID.ClientID + "')";

(Note that the javascript: protocol is only used when you put script in
an URL, e.g. in the href attribute of a link. If you use it in the
onclick attribute, it will instead be interpreted as a label.)

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
Missing Content Placeholder in nested master content page John ASP .Net 2 01-15-2008 11:48 AM
Master-Content in Asp.net - How to set individual Head for each content page Rolf Welskes ASP .Net 7 08-22-2006 02:47 PM
limit on number of content placeholders(which are editable in content pages) in master page nemesis.saurabh@gmail.com ASP .Net 0 05-25-2006 04:44 AM
Error: "Content controls can only be used in a content page" J.Edwards ASP .Net 0 01-20-2006 11:43 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57