How to get the value hidden control of user control in .aspx page

How to get the value hidden control of user control in .aspx page

 

Thanks

srinivas

0
ch
1/9/2009 1:47:19 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
1032 Views

Similar Articles

[PageSpeed] 20

 If its a server control (runat attribute = server) and its markup starts with <asp:HiddenField ID="HiddenField1">, you can just call HiddenField1.Value to get the value stored in it. Even if your hidden field is not a standard asp.net control you can still retrieve the value provided the runat attribute is set to server.

Hope this helps Yes


programming blog
0
deostroll
1/9/2009 2:07:27 PM
Use <%=testhid.ClientId%>

For example getting a reference to the object would look like:

var testid = document.getElementById("<%=testhid.ClientId%>")

object.ClientId returns what the actual html id of the control will be.  This ID can be variable based on the control hierarchy and parent controls.

 


CSR
~ Please Mark as Answer if it solves your query ~
0
SATISD9X
1/9/2009 2:14:15 PM

ch.srinivas1700:
How to get the value hidden control of user control in .aspx page
 

If the HiddenField control resides within a UserControl then you can use FindControl method to access it like below:

 

        HiddenField hidden = (HiddenField)UserControl1.FindControl("HiddenField1");
        if (hidden != null)
        {
            string value = hidden.Value.ToString();
        }
  
Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
1/9/2009 2:19:02 PM

Example showing below, simply expose the hidden field's value attribute as a property for flexibility.

ASPX page:

  

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register src="~/usercontrols/WebUserControl1.ascx" TagPrefix="uc" TagName="UCMyControl" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:UCMyControl runat="server" id="ucMyControl" HiddenFieldValue="test" />
<br />
<span onclick="checkHiddenFieldValue()">Click here to check hidden value</span>
</div>
</form>
<script type="text/javascript">
// here's how to get from client side
function checkHiddenFieldValue()
{
var hid = document.getElementById('<%=ucMyControl.HiddenFieldClientId %>');
if (hid)
{
alert(hid.value);
}
}
</script>
</body>
</html>
 

ASCX page:

 
<%@ Control Language="C#" AutoEventWireup="true" %>
<script runat="server" type="text/C#">
public string HiddenFieldValue
{
get { return hidSomeValue.Value; }
set { hidSomeValue.Value = value; }
}

public string HiddenFieldClientId
{
get { return hidSomeValue.ClientID; }
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
litOutput.Text = HiddenFieldValue;
}
</script>
<asp:HiddenField runat="server" ID="hidSomeValue" />
<asp:Literal runat="server" ID="litOutput" />
 

Jack Yang
.NET Developer
0
jackyang
1/9/2009 2:30:33 PM
Reply:

Similar Artilces:

Accessing server control values of a web user control from ASPX page
Hi, I have created a web user control (ascx) page with several server controls and the web user control included in a aspx page. I have a command button in main aspx page. How can I access values of the controls in web user control from onclick event of the aspx page. Thanks, Chamil. Make the controls on the web user control public.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Could you pl. give me a sample line of code on how to make the control public. thanks, chamil Are you developing inline or with a code-behind?...

Pass values from one user control to a user control on a different aspx page
Hello, I have an aspx page titled Search.aspx. Within this page, I have a user control titled Search.ascx. I want a user to input search terms, then on the click of a button, I want to pass the values to another page (SearchResults.aspx)....which will then display the results in a user control. Can someone please give me some suggestions on how to do this? Thanks a lot! Hello, what you can do is: inside ur usercontrol, create a method that returns a dataset or datareader. that is, since u are searching using the usercontrol, then the result of ur search will be return...

Single page with multiple user web controls VS Multiple page with specific user web controls
I have a question regarding single page with multiple user web controls vs multiple page with specific user web controls   Option 1: I am of the opinion to have multiple pages with specific user web controls and use an object to store all the information as the user navigates through the application. And finally at the end, read this object and save all the information to the backend database.   Option 2: My respected team member suggests that we have only one page, with all the specific user web controls and not use an object, instead show/hide the user web controls based ...

Web Menus / User controls in aspx web page and .aspx C# based web templates
Dear all, I have created several user controls and included in the webpages. (This user control is a navigation menu consisting of images) This has to be included in all webpages. But when i tried to publish i get error messages for them. But i can’t remove since i need these user controls. Error message given below Error 2 The type 'WebUserControl' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\new_latest\d203e69a\d67c356f\App_Web_ijsq-eqk.dll' and 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\new_la...

values of web controls in user control can not be access from other pages???
I have aspx page(brief code: includes ascx file) <%@ Register Src="reseller.ascx" TagName="reseller" TagPrefix="uc1" %> <form id="form1" runat="server"> <uc1:reseller ID="idreseller" runat="server" /> </form> the code for asxc file . i have the PostBackUrl to reseller.aspx <asp:TextBox ID="txtPostCode" runat="server" CssClass="form1" Width="50" MaxLength="4" /> <asp:ImageButton ID="ibtn"  ImageUrl="images/searchbutton.jpg" PostBackUrl="~/reseller.aspx" runat="server"  /> In my reseller page i try to read the post value of control txt...

How to get the HREF value of the Anchor tag in a web page using the web browser control in vb.net
Hi Friends,               i have a webserver control in my application.i load the web browser control on a button click using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click                AxWebBrowser1.Navigate("http://www.rateitall.com/i-322335-.aspx", False) End sub once the page is loaded in the browser i want the <a> HREF value in that page.For example if that page has ...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

Add user control from user control to web page
Hi there, I have a user control, that is inside another user control on a web page. From this user contfol, I need to add something to a place holder on the parent web page. I am having troubles referencing the placeholder correclty. I can get it fine as build time, but on runtime it kicks up the "Object reference not set to an instance of an object" error. Any ideas would be greatly appreciated. -------------------------------------------------------------- protected Civil_and_Corporate.candcadmin._default _default; ------------------------- Control objControl...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

How to get values from user control onto .aspx page
Hi all, I have a date user control that has three dropdownlists, one for months, one for days, and the last for years. The control does all the cool leap year stuff. woo hoo. I want to be able to use the control on a page and retrieve the values from it on a click event from the parent page. I have read all kinds of posts that show how to do this with a click event in the user control, but haven't found any for what I need. please help as I am slowly, but surely headed for insanity over this. Sincerely, mark Here's the vb for the control itself. Public Class ...

cant get web user control page value
i have a page web user control (ascx file), name =criteria in the ascx page i have a dropdownlist, name = Field1 the ascx page have a function Function GetValue() as string    Return Field1.SelectedItem.text Ebd Function now i include the ascx file to my web form with button ''''button at the web form not ascx file in button click events Dim Str as String Dim objCriteria as new Criteria  ' Criteria is ascx page class name Str = objCriteria.GetValue But at runtime i get an error say null reference exception how to solve the problem? i using VS 2005 and .ne...

Web page .aspx is slow when loading. Pages have web user controls on them that are loaded dynamically
I have written a web application using VS 2003. Several of my forms have web user controls on them. The controls are loaded dynamically at runtime. The problem is that the web pages are very slow to load. Does anyone know if there is a way to speed up the pages being loaded into the browser? Here is an example of some code I use to dynamically load the controls:  private void Page_Load(object sender, System.EventArgs e)  {   // Put user code to initialize the page here   // Put user code to initialize the page here    Co...

How to get a variable from a web page (.aspx) in a user control (.ascx)
I have a web page with a dropdownlist and a usercontrol.  I would like the usercontrol to be able to read what the selected value is in the dropdownlist.   Any ideas on how this can/should be done are greatly appreciated. I'd suggest that you expose a public property on the Control and have the Page set this when the page does it's postback, for the control to consume. I have a page where I need to get the values from a DropDown prior to postback so I've got a public String and I set the variable whenever ddlYear_SelectedIndexChanged is called.  I also set i...

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

Web resources about - How to get the value hidden control of user control in .aspx page - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Fitness is ‘escalating beyond control'
HEALTH experts are warning parents that obsessive exercise can be linked to life-threatening eating disorders in teens, amid an explosion of ...

Otway fire still out of control but no threat to Falls Festival
Firefighters are battling to contain an out-of-control Great Otway National Park fire ahead of an expected hot and windy weather spike on Christmas ...

Review: Sugr Cube, the cute wooden portable AirPlay speaker with gesture controls
... rarer, pretty ones even rarer and the Sugr Cube goes one step further in its bid to stand out from the crowd: it offers gesture-based control. ...

North Korea's Red Star OS leaves the government in control of computers
... least not by most people's standards. Like China , the socialist state is keen to embrace the power of the internet, but wants to retain control ...

You can control this family’s Christmas lights over the Internet
... Horrible disaster waiting to happen? You be the judge. You've never met Ken or Rebecca-Ellen and you probably never will. But you can control ...

This is how Amazon is taking control of delivery – and taking it away from UPS
As Amazon searches for ways to speed up delivery, the company this year made big strides toward cutting out the middle man and establishing a ...

The 10 Dumbest Gun Control Political Cartoons of 2015
Perhaps not just 2015. Maybe the dumbest of all times . Say, you mean stricter gun control laws will stop terrorism? No one tell the 300+ victims ...

You can control this family's Christmas lights over the internet and the results are mesmerising
... as they see fit. Visitors are greeted with a live webcam of the Fairbanks, Alaska house — pictured above — as well as a bank of controls for ...

Afghan officials: Key district besieged by Taliban still under state control
"Taliban rumors that they have captured the district are not true," says local official trapped for 3 days before government reinforcements arrived ...

Resources last updated: 12/27/2015 11:39:53 PM