473,325 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

asp.net HiddenField ClientId

Hi!

I would like to write something in Javascript to HiddenField:
<asp:HiddenField ID="hiddenMy" runat="server" Value="" />
And in the code behind read this value.

But this HiddenField is in user control. I use this control in many pages
and in every page this field has different value..
I don't know why, but it's error when I do:
var hidden = document.GetElementById('<%= this.gvClient.ClientID %>');

How can I find ClientId of the HiddenField ?

Thanks for help
Oct 22 '08 #1
7 11479
"imbirek8" <im******@op.plwrote in message
news:gd**********@news.onet.pl...
I would like to write something in Javascript to HiddenField:
<asp:HiddenField ID="hiddenMy" runat="server" Value="" />
And in the code behind read this value.

But this HiddenField is in user control. I use this control in many pages
and in every page this field has different value..
I don't know why, but it's error when I do:
var hidden = document.GetElementById('<%= this.gvClient.ClientID %>');

How can I find ClientId of the HiddenField ?
You can use hiddenMy.ClientID.Replace("_", "$")
Oct 22 '08 #2
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:en****************@TK2MSFTNGP05.phx.gbl...
[...]
>How can I find ClientId of the HiddenField ?
You can use hiddenMy.ClientID.Replace("_", "$")
[...]

I don't understant what exacly it would do..

Oct 22 '08 #3

"imbirek8" <im******@op.plwrote in message
news:gd**********@news.onet.pl...
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:en****************@TK2MSFTNGP05.phx.gbl...
[...]
>>How can I find ClientId of the HiddenField ?
You can use hiddenMy.ClientID.Replace("_", "$")
[...]

I don't understant what exacly it would do..
The ClientID property returns an ID that separates its various parts
with "_", such as "ctl00_ctrlA1_rptB1_ctl00_ibB1", but the Name that is
actually rendered into the html uses "$" to separate the same parts, such as
"ctl00$ctrlA1$rptB1$ctl01$ibB1". At first I thought that you were doing a
finding the element by Name, so you would have needed the previous
replacement to find the control on the client side.

Upon rereading your message, I see that this is not the case. You mention
that you are doing document.GetElementById('<%= this.gvClient.ClientID
%>'); and that you get an error, but you don't mention what the error is.
You also don't mention wether you are writing this code in the markup of the
Page or the UserControl. If you are writing it on the Page, the "this" is
interpreted on the page class, so "this.gvClient" needs to refer to a public
field or property on the page, it won't work if gvClient is inside a
usercontrol that is inside the page, since this is not automatically visible
to the page class. You may wish to add a public property to expose the
information that you then render in the <%= ... %>.

Oct 23 '08 #4
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2****************@TK2MSFTNGP05.phx.gbl...
[...]

And what about this idea. I would like to add for example label and set
style="display:none;". and in JavaScript change the the text and in code
behind read new value. I have:
<asp:Label ID="labelSelectedRow" runat="server" Text="aaa" />
and i JavaScript I do:
(document.getElementById('<%= this.labelSelectedRow.ClientID %>')).Text=
"bbb";

but nothing has changed... why ?

Thanks for help

Oct 27 '08 #5
"imbirek8" <im******@op.plwrote in message
news:ge**********@news.onet.pl...
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:%2****************@TK2MSFTNGP05.phx.gbl...
[...]

And what about this idea. I would like to add for example label and set
style="display:none;". and in JavaScript change the the text and in code
behind read new value. I have:
<asp:Label ID="labelSelectedRow" runat="server" Text="aaa" />
and i JavaScript I do:
(document.getElementById('<%= this.labelSelectedRow.ClientID %>')).Text=
"bbb";

but nothing has changed... why ?
It *should* change... on the display in the browser, if it weren't
hidden. But you can't read it back in the code behind because the label does
not get posted back from the browser into the server.
You can do it with a HiddenField, which is rendered as <input
type="hidden"(or you can use a TextBox with style="display:none;"). If you
change its value in javscript, it will be available to the server after the
form gets submitted.

Oct 27 '08 #6
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:eO**************@TK2MSFTNGP06.phx.gbl...
[...]
I do not understand anything. I have the simpliest code I can have and it
doesn't work. I can't see even alert.. in firebug I don't have any error.
Why it doesn't work ?

<body>
<script type="text/javascript">
function click()
{
alert('here1');
(document.getElementById('<%=this.txtSelectedRow.C lientID%>')).Text
= "bbb";
}
</script>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSelectedRow" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="click()" />
</div>
</form>
</body>

Thanks for help

Oct 27 '08 #7
Two changes:

- First, change the name of the function from "click" into something else,
such as "b_click" (click is already in use somewhere else in the hierarchy
of dhtml objects).

- Second, you should use ".value" instead of ".Text". We are using the
client-side object model, not the server-side. In other words, asp:TextBox
has a .Text property, but it gets rendered into the browser as an <input
type=text.../>, which has a .value but not a .Text.

I have copied a corrected version at the bottom.
"imbirek8" <im******@op.plwrote in message
news:ge**********@news.onet.pl...
"Alberto Poblacion" <ea******************************@poblacion.orgwro te
in message news:eO**************@TK2MSFTNGP06.phx.gbl...
[...]
I do not understand anything. I have the simpliest code I can have and it
doesn't work. I can't see even alert.. in firebug I don't have any error.
Why it doesn't work ?

<body>
<script type="text/javascript">
function click()
{
alert('here1');
(document.getElementById('<%=this.txtSelectedRow.C lientID%>')).Text
= "bbb";
}
</script>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSelectedRow" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="click()" />
</div>
</form>
</body>

Thanks for help

<body>
<script type="text/javascript">
function b_click()
{
alert('here1');
(document.getElementById('<%=this.txtSelectedRow.C lientID%>')).value
= "bbb";
}
</script>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSelectedRow" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="b_click();" />
</div>
</form>
</body>
Oct 28 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Maras | last post by:
Hello, as we know VB is not case sensivity. I have a following problem, I have to send to another server few parametrs by post or get method, one of them MUST be a "clientID", it's preety...
2
by: Neo Geshel | last post by:
After pouring over about a dozen sites that clearly dealt with ClientID all by itself, I came to the realization that about 2/3+ of them were doing it wrong. It is indeed impossible to grab the...
9
by: Kevin Blount | last post by:
Here's the code I tried, and found it failed... <form runat="server" method="post" name="CreditCardForm" id="CreditCardForm"> <% foreach (object item in Request.Form) { if...
3
by: sklett | last post by:
I've added a HiddenField control to my page and some javascript to show it's value in an alert box when a button is pressed. The value that is displayed in the alert box is correct, but when I...
3
by: Jeff | last post by:
Hey ASP.NET 2.0 Below you see the code I'm having problem with. In the Open_Message event/method I want to get the value of the HiddenField at the row in the repeater control I clicked.... my...
1
by: Milkstr | last post by:
I have a repeating region with a hiddenfield on each line, i want to start a counter in my reapeating reagion so that the hiddenfield becomes unique on each line. So that is the reapeating region goe...
1
by: RSH | last post by:
I have a situation where I have a user control (Called TopOrangeMenu) that has an Hidden HTML Field called "txtU" I am trying to get at the value of that hidden field control from within the...
1
by: KBTibbs | last post by:
My ASP.NET page generates some HTML, then sticks it into a hiddenfield so a javascript can access it and write it to a popup window. I had to disable validation for this page, as HTML inside a...
1
by: win | last post by:
I've created a formview and bind the columns. The column ModifyUser should not be be displayed so that I've modified from Textbos to HiddenField. How can I change the bind value of a Hiddenfield...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.