473,566 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp.net HiddenField ClientId

Hi!

I would like to write something in Javascript to HiddenField:
<asp:HiddenFiel d 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.GetEle mentById('<%= this.gvClient.C lientID %>');

How can I find ClientId of the HiddenField ?

Thanks for help
Oct 22 '08 #1
7 11498
"imbirek8" <im******@op.pl wrote in message
news:gd******** **@news.onet.pl ...
I would like to write something in Javascript to HiddenField:
<asp:HiddenFiel d 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.GetEle mentById('<%= this.gvClient.C lientID %>');

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

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

Oct 22 '08 #3

"imbirek8" <im******@op.pl wrote in message
news:gd******** **@news.onet.pl ...
"Alberto Poblacion" <ea************ *************** ***@poblacion.o rgwrote
in message news:en******** ********@TK2MSF TNGP05.phx.gbl. ..
[...]
>>How can I find ClientId of the HiddenField ?
You can use hiddenMy.Client ID.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_r ptB1_ctl00_ibB1 ", but the Name that is
actually rendered into the html uses "$" to separate the same parts, such as
"ctl00$ctrlA1$r ptB1$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.GetEle mentById('<%= this.gvClient.C lientID
%>'); 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.gvCli ent" 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.o rgwrote
in message news:%2******** ********@TK2MSF TNGP05.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="labelSelect edRow" runat="server" Text="aaa" />
and i JavaScript I do:
(document.getEl ementById('<%= this.labelSelec tedRow.ClientID %>')).Text=
"bbb";

but nothing has changed... why ?

Thanks for help

Oct 27 '08 #5
"imbirek8" <im******@op.pl wrote in message
news:ge******** **@news.onet.pl ...
"Alberto Poblacion" <ea************ *************** ***@poblacion.o rgwrote
in message news:%2******** ********@TK2MSF TNGP05.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="labelSelect edRow" runat="server" Text="aaa" />
and i JavaScript I do:
(document.getEl ementById('<%= this.labelSelec tedRow.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"(o r 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.o rgwrote
in message news:eO******** ******@TK2MSFTN GP06.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.getEl ementById('<%=t his.txtSelected Row.ClientID%>' )).Text
= "bbb";
}
</script>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSelected Row" 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.pl wrote in message
news:ge******** **@news.onet.pl ...
"Alberto Poblacion" <ea************ *************** ***@poblacion.o rgwrote
in message news:eO******** ******@TK2MSFTN GP06.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.getEl ementById('<%=t his.txtSelected Row.ClientID%>' )).Text
= "bbb";
}
</script>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSelected Row" 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.getEl ementById('<%=t his.txtSelected Row.ClientID%>' )).value
= "bbb";
}
</script>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtSelected Row" 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
2506
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 simple, but in VB .NET there is a property ClientID and I get an error, a conflict beetwen my clientID and ClientID of MyBase class aspx code: ****
2
1500
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 Client ID of a form field from within a DataGrid like this: <%= FormFieldID.ClientID %>. At least, not without extra work. How did I do this? I...
9
4660
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 (item.ToString().IndexOf("__") != 0) { //Response.Write(item + " = " + Request.Form +
3
1962
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 post the form the value for the HiddenField control is empty. I'm pretty new to ASP.net so I'm not really sure what could cause this. I'm using...
3
6846
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 goal is to get the id (not a control Id, but an id related to a database record) of a row in the repeater control. I don't want to use Get... I've...
1
1485
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 to say 10 records i actually have 10 hiddenfields with unique names. I thought i could just set a variable at the start of the loop that increments...
1
3434
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 User Control. Hidden Field Control as it apears in the HTML of the User Control: <INPUT id="txtU" type="hidden" runat="server"> Trace Output...
1
2039
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 field triggers ASP.NET's cross-site scripting security. Now, this was all working well and good until I changed my navigation menus from plain images...
1
4542
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 and update the formview? Thank you
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.