By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,700 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,700 IT Pros & Developers. It's quick & easy.

Displaying hidden variable values in text box on button click

P: 30
Dear All
Iam new to asp.net. I had a problem. I have a multiline textbox and link buttons say firstname,lastname, Emails and corresponding hidden fields with each textbox.My problem is that suppose i typed some text afterwards i press linkbutton firstname(say).so the value in hidden field associated with this link button will display in the text box.

Thankx In Advance

Regards
Yogesh
Jun 24 '08 #1
Share this Question
Share on Google+
18 Replies


Plater
Expert 5K+
P: 7,872
What?
I'm not clear with what you are trying to do, but javascript should be able to take the value from one control(hidden or otherwise) and put it in another control
Jun 24 '08 #2

P: 30
What?
I'm not clear with what you are trying to do, but javascript should be able to take the value from one control(hidden or otherwise) and put it in another control
I want to display value of hidden field on button click in textbox
Jun 24 '08 #3

Plater
Expert 5K+
P: 7,872
Then javascript would be the way of it.

Something like:
Expand|Select|Wrap|Line Numbers
  1. var theval = document.getElementById("MyHiddenfieldName").Value;
  2. document.getElementById("TheTextboxToSet").Value = theval;
  3.  
Jun 24 '08 #4

P: 30
Then javascript would be the way of it.

Something like:
Expand|Select|Wrap|Line Numbers
  1. var theval = document.getElementById("MyHiddenfieldName").Value;
  2. document.getElementById("TheTextboxToSet").Value = theval;
  3.  
Thankx
Again there is an issue if u can help i want that, Suppose initailly i enter text in text box then i click on a linkbutton then the value of hidden field will appear in the textbox after the entered text
Thankx in advance
Yogesh
Jun 25 '08 #5

10K+
P: 13,264
Thankx
Again there is an issue if u can help i want that, Suppose initailly i enter text in text box then i click on a linkbutton then the value of hidden field will appear in the textbox after the entered text
Thankx in advance
Yogesh
Javascript will do it again. The coding is similar to what Plater gave you above. Try it and post your code if you get problems.
Jun 25 '08 #6

P: 30
<script language="javascript" type="text/javascript" >
function DisplayHiddenValue()
{
debugger;
var theval = document.getElementById('hdnfld').value;
alert(document.getElementById('hdnfld').value);
document.getElementById('txtdisplay').value = theval;
}
</script>

My problem is suppose i enter text intially Hello afterwards the value in hiddenfield is World When i call above javascript function it will display Hello World
Jun 25 '08 #7

10K+
P: 13,264
<script language="javascript" type="text/javascript" >
function DisplayHiddenValue()
{
debugger;
var theval = document.getElementById('hdnfld').value;
alert(document.getElementById('hdnfld').value);
document.getElementById('txtdisplay').value = theval;
}
</script>

My problem is suppose i enter text intially Hello afterwards the value in hiddenfield is World When i call above javascript function it will display Hello World
Moving to Javascript forum.
Jun 25 '08 #8

hsriat
Expert 100+
P: 1,654
Expand|Select|Wrap|Line Numbers
  1. var txt = document.getElementById('txtdisplay');
  2. txt.value = txt.value + ' ' + theval;
Jun 25 '08 #9

P: 30
Expand|Select|Wrap|Line Numbers
  1. var txt = document.getElementById('txtdisplay');
  2. txt.value = txt.value + ' ' + theval;
Thankx.
Can we take link button and hidden field in gridview and take values from database for our above scenario
Jun 25 '08 #10

hsriat
Expert 100+
P: 1,654
Sorry, could not get that. If you can explain...
Jun 25 '08 #11

P: 30
Sorry, could not get that. If you can explain...
hi
Actually i mean right now iam just taking one link button and one hidden field
and applied the above javascript.I want to take more than one link button and hidden field so can i take it in gridview itemtemplate column and call the above javascript
Jun 25 '08 #12

hsriat
Expert 100+
P: 1,654
hi
Actually i mean right now iam just taking one link button and one hidden field
and applied the above javascript.I want to take more than one link button and hidden field so can i take it in gridview itemtemplate column and call the above javascript
Of course you can. You need to make a general function and pass the required arguments to it.

If you can show me HTML part of the grid, I can surely tell you what arguments you need to give to the function.
Jun 25 '08 #13

P: 30
Of course you can. You need to make a general function and pass the required arguments to it.

If you can show me HTML part of the grid, I can surely tell you what arguments you need to give to the function.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TextBoxDisplay.aspx.cs" Inherits="TextBoxDisplay" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript" >
function DisplayHiddenValue()
{
debugger;
var theval = document.getElementById('hdnfld').value;
alert(document.getElementById('hdnfld').value);
document.getElementById ('txtdisplay').focus();
var txtval= document.getElementById('txtdisplay').value +" "+ theval;
alert(txtval);
document.getElementById('txtdisplay').value=txtval ;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<asp:TextBox ID="txtdisplay" runat="server" TextMode="MultiLine" Rows="10"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:LinkButton ID="lnkbtn" runat="server" PostBackUrl="javascript:void(0)" OnClientClick="DisplayHiddenValue();">LinkButton</asp:LinkButton>
</td>
<td>
<asp:HiddenField ID="hdnfld" runat="server" Value="Diaspark" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Jun 25 '08 #14

hsriat
Expert 100+
P: 1,654
It would be better if you post the generated HTML (the one which you see in the view source thingie)
Jun 25 '08 #15

P: 30
It would be better if you post the generated HTML (the one which you see in the view source thingie)

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title>
<script language="javascript" type="text/javascript" >
function DisplayHiddenValue()
{
//debugger;
var theval = document.getElementById('hdnfld').value;
alert(document.getElementById('hdnfld').value);
document.getElementById ('txtdisplay').focus();
var txtval= document.getElementById('txtdisplay').value +" "+ theval;
// alert(txtval);
document.getElementById('txtdisplay').value=txtval ;
}
</script>
</head>
<body>
<form name="form1" method="post" action="TextBoxDisplay.aspx" id="form1">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTQwMTM3OTkyOWRkiPXffNMTKaJE+dtXj9BK4x/GGq4=" />
</div>

<script type="text/javascript">
<!--
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
// -->
</script>


<script src="/CustomValidation/WebResource.axd?d=0G1lpC1Mw-WqUmMptOtNRA2&amp;t=633366975968750000" type="text/javascript"></script>

<div>
<table>
<tr>
<td>
<textarea name="txtdisplay" rows="10" cols="20" id="txtdisplay"></textarea>
</td>
</tr>
<tr>
<td>
<a onclick="DisplayHiddenValue();" id="lnkbtn" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;lnkbtn&quot;, &quot;&quot;, false, &quot;&quot;, &quot;javascript:void(0)&quot;, false, true))">LinkButton</a>
</td>
<td>
<input type="hidden" name="hdnfld" id="hdnfld" value="Diaspark" />
</td>
</tr>
</table>
</div>

<div>

<input type="hidden" name="__PREVIOUSPAGE" id="__PREVIOUSPAGE" value="6iXjEN7CVNX7ftfWFwReRvDYFE0SHoqpfcvm4FSeezQ hthmN-wye2hVrn3EoP1md0" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKSn9TUCwLMvPSGAQLR2ZPSAQKWlt2cDQdCdGeC/cVgAcyhuTLXmtRos/n+" />
</div></form>
</body>
</html>[/HTML]
Jun 25 '08 #16

acoder
Expert Mod 15k+
P: 16,027
hsegoy1979, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future. Thanks!
Jun 25 '08 #17

P: 30
Thankx a lot

I have done it

Yogesh
Jun 25 '08 #18

hsriat
Expert 100+
P: 1,654
Thankx a lot

I have done it

Yogesh
That's really good. :)
Jun 25 '08 #19

Post your reply

Sign in to post your reply or Sign up for a free account.