How to get the value from a textbox of a datagrid template column while in edit mode using client javascript

Hi,

I have added a template column to my datagrid,
and in EditItemTemplate tags i am displaying an asp textbox
<EditItemTemplate>
<asp:TEXTBOX id=TextBox1 Text='<%# Container.DataItem("MyDataField) %>' Runat="server"></asp:TEXTBOX>
</EditItemTemplate>
i need to get the value of the textbox using a client side scripting language like Javascript.
i tried the document.forms[0].TextBox1.value option but does not work
I need a solution for this
Waiting for replies.
0
leonardniit
4/23/2004 3:08:35 PM
asp.net.client-side 24353 articles. 1 followers. Follow

6 Replies
1127 Views

Similar Articles

[PageSpeed] 2

i'm trying to figure out the same thing, my current method is by creating the script on the server when the user is done with the dialog, then sending it back:

Dim sScript As String
sScript = "<script>window.opener.document.forms(0).TextBox1.value="
sScript += TextBox1.Text
sScript += "';self.close()</script>"
Response.Write(sScript)
(this code goes on the popup window.)
....here's what i tried to do in javascript that didn't work
window.opener.document.forms(0).item('TextBox1',0).value="heh";
this will return "heh" to the parent textbox
window.opener.document.forms(0).item('TextBox1',0).value = TextBox1.value;
this will not return the value of textbox1 to the parent.. not sure why, i tried assigning TextBox1.value to another variable, and it would not get the value, this seems like it would be a simple procedure but i can't figure it out.. now i'm waiting for replies too ;\
0
adams_antics
4/24/2004 5:47:46 PM
I wanted to do the same thing, so that I could validate the entry client-side before submitting the entry.  Here's what I had to do:

I added a handler for the datagrid prerender event. In that handler, I looped through the cells of the edited row creating client-side code for the unique ID of each object (I use the vbCrLfs for readability, but they aren't necessary). After I had created all of that I used the page objects RegisterClientScriptBlock method to write it all out. Then, in my validation code, I look for those client-side variables to find the controls. Here's my code:
Public Sub dtgFacts_PreRender(ByVal sender As Object, ByVal e As EventArgs) _
Handles dtgFacts.PreRender
Dim nItem As Integer = 0
If dtgFacts.EditItemIndex > -1 Then
Dim sElementNames As String = _
"<script language=""javascript"" type=""text/javascript"">" & _
"<!--" & vbCrLf & _
"var sFactTextTB = '" & dtgFacts.Items(dtgFacts.EditItemIndex).Cells(0).Controls(1).UniqueID & "';" & vbCrLf & _
"var sPublishTB = '" & dtgFacts.Items(dtgFacts.EditItemIndex).Cells(1).Controls(1).UniqueID & "';" & vbCrLf & _
"var sExpireTB = '" & dtgFacts.Items(dtgFacts.EditItemIndex).Cells(2).Controls(1).UniqueID & "';" & vbCrLf & _
"-->" & vbCrLf & _
"</script>" & vbCrLf
RegisterClientScriptBlock("elementnames", sElementNames)
CType(dtgFacts.Items(dtgFacts.EditItemIndex).Cells(3).Controls(0), _
LinkButton).Attributes.Add("onclick", "return validateForm();")
End If
End Sub
What I did in the client-side code was something like:
function validateForm()
{
var oFactTextTB = eval(sFactTextTB);
if (oFactTextTB.value.length < 10)
{alert('Fact text must be at least 10 characters'); return false;}
}
Hope this helps.
Dave
0
davemccall
4/26/2004 3:58:14 PM

Try this:
document.getElementById('DataGridx__ctlx_TextBox1').value
where DataGridx__ctlx_TextBox1 is the new id of TextBox1 when rendered to the client browser. In your case you will have to view the source to get the actual id.
0
riggs321
4/27/2004 4:18:39 PM
i think you can solve this process by adding an onitemdatabound event handler for the edititems within your grid. the onitemdatabound fires as each row is actually being outputted so its perfect for catching the client side ID's.

within this event handler you can retrieve the client side ID of the textbox within your editable row. you can then use this client ID within some javascript code which you can attach to your submit button dynamically.
you would attach this code to a submit button to perform client side validation. however be warned: it is good practice to also perform server side validation as well at some point as an extra security precaution. you can also use this logic to transfer textbox values to popup pages. let me show you what i mean in code (C#):

private void dataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
// lets make sure we are only applying this logic to the edititemtemplate
if (e.Item.ItemType == ListItemType.EditItem)
{
// get the client ID of your textbox
string strTextBoxName = e.Item.FindControl("yourtextboxName").ClientID;
// get the client ID of your submit button
Button yourButton = (Button) e.Item.FindControl("yourbuttonName");
// use the client ID and dynamically include it to a javascript function within the 'onClick' property of the button
yourButton.Attributes.Add("onClick", "JavascriptPopUpFunction('" + strTextBoxName + "')");
}
}

is this what you're after?

0
Wee
4/28/2004 9:42:07 AM
Hi everybody,

thanx for all ur replies, riggs321 solution works absolutely fine.
-Harry Anthony
0
leonardniit
4/29/2004 5:46:22 AM
Okay. This solution will work if you know the edititemindex. 

But what can you do if you don´t know this.
Do you know a possiblity to get this ?
Mirco
0
mrogo
5/4/2004 12:46:09 PM
Reply:

Similar Artilces:

Get the Dropdownlist text and value using Javascript from client side
Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)            &nb...

Recalculating Column Values in Data Grid on Client Side using JavaScript or ....?
Hello I am using Datagrid and i have 3 template columns in it. i want to calculate sum of first 2 columns in 3 rd columns... first 2 columns values are comming from database.. if user change some values in grid then sum should be recalculated on client side thanks    ...

Data Grid:Client Side Recalculating Column Values using JavaScript or ....?
Hello I am using Datagrid and i have 3 template columns in it. i want to calculate sum of first 2 columns in 3 rd columns... first 2 columns values are comming from database.. if user change some values in grid then sum should be recalculated on client side thanks     1. In the 3rd template use the textbox, show the sum of the 2 columns from the database. <code> <ItemTemplate><asp:TextBox Text='<%#Container.DataItem("First") + Container.DataItem("Second")%>......</ItemTemplate> </code> 2. Attach client side scripts to the textboxes in t...

How to write data to a file in client side using javascript or someother client side scripting language.
Hi, I would like to know how to write a data to a client side file using javascript or someother client side scripting language. The file type expected is ini file. txt file would also be appreciable. Thanks in advance.   If the site is a trusted and you are running IE then you could try http://www.w3schools.com/asp/asp_ref_filesystem.asp The Old Sewing FactoryThat twitter nonsense. You can write to the server, but not to the client's machine.  Being able to do so would be a huge security breach.When you ask a question, remember to click "mark as answered"...

How to use client-side script(javascript) in DNA using .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script> objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ...... }   szUrl = "http://ServerNa...

how do i get selectedValue of drop down list server side if i am populating it using client side javascript?
 Hi All.I am populating a drop down list client side using: The drop down list is populated based on a selection of another drop down list. ddlList.options[i] = new Option(1,2); as an exampleThe populating is done as i need it to. However, a button click event i am trying to get the selectedValue of the ddlList. However, it doesn't give me it. It only gives me the selectedValue of the drop down list on first rendering. Any ideas on how i can get it?   Could You paste some code? That would be helpful. Thanks S@ss (Shashi Shekhar Singh)My BlogPlease mark a post as ANSWER ...

Datagrid:--> Adjusting column width in edit mode without using template column?
Hello All, I have a datagrid that is populated with data from a database programmatically. It is currently equipped with an Edit command column. When the edit button is clicked the datagrid expands as the update, cancel, and edit-textboxes appear in the grid. I have currently been binding my datasource to the grid without using template or bound columns. Is there a way to maintain my initial datagrid size even when the edit command button is clicked or do I have to reprogram my datagrid with template columns? If I could get some assistance in this area it would be great!! Can you paste...

Get textbox value in client side
My problem is that in my ascx file i have a textbox & a input buttom with a javascript function that will validate the textbox: .... <script lang="javascript"> function Test() { if (document.all.txt1.value == "") { alert(); return; } } </script> .... <asp:textbox id="txt1" runat="Server"></textbox> <input type=button id="cmd1" onclick="javascript:Test();" value="Add"> .... But the function don't work, because the textbox control isn't...

Columns arrangement in DataGrid
Dear Friends, Please give me a solution for below problem, I have to bind a data table to a DataGrid, I will be not knowing no of columns and data until runtime, so I did not configured columns widh at design time. Now my client is asking me like, he want a facility to alter the column width at runtime, I mean he want to change columns width in client (IE), like window application. So, will you please tell me how to provide facility to change column width of a datagrid at client by user ? Thank you, Sreedhar Nasum.     Hi:   DataGrid will render as <table>. Ta...

Get Value from template column textbox in Datagrid
Sorry to come back with this request, but I am unable to get the correct info on how to access a value in a datagrid. The column in question is a textbox. I am trying to edit the row and use the value from the textbox (LocationID) as a filter for an SQL statement that will load a DDL for that location. When the Edit is executed I get the correct e.item.index value but don't know where to go from there. It has been suggested that I need to rebind the grid once in edit and then I should be able to get the LocationID, create the SQL and rebind before displaying the grid for editting. It has be...

Getting Textbox Watermark Text in client side javascript
Can somebody tell me how I can go about grabbing the Text value of a TextBoxWatermark control from client side javascript?  I need to make a comparison/validation if a text box has been filled out (non-blank) and of course the watermark fills in the text value of the text box when grabbing the property (of the text box) per javascript? So, I need to somehow grab the text from the watermark in javascript and then compare to the text box contents to see if the text in the textbox is the water mark text or not.  Any information would be greatly appreciated.  Thanks!  Th...

Getting Value from Client-side InputBox to .net variable
hi, im doing a login page for our timekeeping. Since there's no msgbox available on asp.net, im doing it dynamically via javascript. How do i Get the value frm a dynamically written javascript (such as inputbox) to a .net variable? here's the logic of my program, user logs in hits the button and sub-routine Login will be fired, if user is late -- call Check_Late Sub, this is whre the client-side script was built -- then after that i wanted to be able to get the value from an inputbox. '// if button login clicked Sub Login(Sender As Object, E As EventArgs) .......

attaching client side script to an edit mode textbox
i have a problem to find out how to do this: i need to be able to attach a client side jscript to a textbox of the row which is put into the edit mode and apply some business rules. There are several rows in my datagrid and when the user clicks 'edit' on a row: that row goes into the 'edit mode' and then he/she will be able to change the value ( which is a decimal number ) in one of the textboxes and then the client side script will have the duty to keep the total of the changed value and the value of the same column of the previous row . To show the situation: -------------Co...

How to use client-side script(javascript) in .Net Remoting
Hi all,     It was known that SAO and Singleton object about .Net Remoting. When I Create an object in server side and hosting in IIS's virtual directory,I want to use javascript asynchronous invoking the remote object by HTTP channel, 80 port and SOAP formatter just like XMLHTTP invoking web service. My code as following, <script>  objXmlDoc = new ActiveXObject("Msxml2.DOMDocument"); objHttp = new ActiveXObject("Msxml2.XMLHTTP"); strEnvelope = ?? objHttp.onreadystatechange = function() { ......  }    szUrl = &...

Web resources about - How to get the value from a textbox of a datagrid template column while in edit mode using client javascript - asp.net.client-side

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook Open-Sources JavaScript Static-Type Checker Flow
The latest software to be open-sourced by Facebook is Flow , a static-type checker for JavaScript . (more…) New Career Opportunities Daily: ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

JavaScript
The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Facebook App Devs Get Javascript
It has been an oft-lamented fact of the Facebook Platform thus far in its life that, in order to use all but the most simple of Javascript functionality–the ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken . blog.mozilla.org/research/2014/… ...

Resources last updated: 12/31/2015 11:01:25 PM