|
-
Feb 14th, 2005, 01:40 AM
#1
Thread Starter
Lively Member
Javascript In Ascx file
Hi,
I have an ascx web user control page. In that, I am having one text box server control. In the javascript file inside the ascx file, I am trying to access the textbox as :
document.getElementById('txtAddCode').value=var_Amtcode;
When I add this ascx to another aspx page and try to call the javascript method, the above line retuens an error becoz document.getElementById returns null.
If the textbox is an HTML control, it works fine. But I need this as a server control only. Even if I select the textbox as "run as server control", then also the error comes.
How to solve this issue ?
Thanks in advance...
Everything I code, is a piece for Museum.
-
Feb 14th, 2005, 02:08 AM
#2
Re: Javascript In Ascx file
Create the entire javascript function in your codebehind. When specifying the ID of the textbox, use textboxname.ClientId.ToString instead.
-
Feb 14th, 2005, 02:13 AM
#3
Thread Starter
Lively Member
Re: Javascript In Ascx file
 Originally Posted by mendhak
Create the entire javascript function in your codebehind. When specifying the ID of the textbox, use textboxname.ClientId.ToString instead.
Hi,
Thankx for your reply.
Can you please elaborate on that ? Means, do you mean to write the javascript method in the aspx page ? then also the same error comes. If I put another text box server control in the aspx page with the same name as in the ascx page, it works. But the method takes the control in the aspx page, not of the ascx page.
Do I need to qualify the text box in the Javascript method ? If yes, then how ?
Thankx in advance.
Everything I code, is a piece for Museum.
-
Feb 14th, 2005, 02:28 AM
#4
Re: Javascript In Ascx file
First, answer these questions:
When do you want the js function to run? What is it for?
Does the textbox already exist in the ASCX?
Where are you placing the javascript, in the ASCX or ASPX?
Show the code you implemented for this.
-
Feb 14th, 2005, 02:36 AM
#5
Thread Starter
Lively Member
Re: Javascript In Ascx file
 Originally Posted by mendhak
First, answer these questions:
When do you want the js function to run? What is it for?
Does the textbox already exist in the ASCX?
Where are you placing the javascript, in the ASCX or ASPX?
Show the code you implemented for this.
Hi,
Thanks for your quick response.
1. I am having one third party grid to show data from the database. When the user clicks on any of the rows, I need to show the selected row's data in some textbox(s). So, I have written a javascript method and mapped it to the click event of the grid.
2. Yes, the control is present in the ASCX page. (Server side textbox control).
3. The javascript method I placed in the ASCX page. But, even if I place the method in the ASPX page, the same error comes.
4.
Code:
function dg1_CellClickHandler(gridName, cellId, button){
var oCell = igtbl_getCellById(cellId);
// get reference to row object
var oRow = igtbl_getRowById(cellId);
var_Amtcode = oRow.getCellFromKey("Code").getValue();
var_AmtDesc = oRow.getCellFromKey("Description").getValue();
document.all['txtAddCode'].value = var_Amtcode; //This is giving error.
}
Everything I code, is a piece for Museum.
-
Feb 14th, 2005, 05:19 AM
#6
Re: Javascript In Ascx file
Alright. Now, run the application again, then view the source of the output. Look for the txtAddCode <INPUT> element.
AFAIK, txtAddCode should not be present with the same name. Instead, it should have some other name. Which is why I was saying that this code:
PHP Code:
function dg1_CellClickHandler(gridName, cellId, button){
var oCell = igtbl_getCellById(cellId);
// get reference to row object
var oRow = igtbl_getRowById(cellId);
var_Amtcode = oRow.getCellFromKey("Code").getValue();
var_AmtDesc = oRow.getCellFromKey("Description").getValue();
document.all['txtAddCode'].value = var_Amtcode; //This is giving error.
}
Should be generated in your codebehind.
Make sense?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|