473,396 Members | 1,860 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,396 software developers and data experts.

How to get value of hiddenfield from ascx.cs page to aspx.cs page

Check.aspx code is
Expand|Select|Wrap|Line Numbers
  1. <%@ Register TagName="TopBar" TagPrefix="CRS" Src="~/Demo.ascx" %>
  2. ---
  3. <div>
  4. <CRS:TopBar ID="Hide" runat="server"/>
  5. </div>
Check.aspx.cs code is
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.   Demo uc = (Demo)Page.LoadControl("Demo.ascx");
  4.   HiddenField hide = (HiddenField)uc.FindControl("hidden1");
  5.   Response.Write("--- " + hide.Value + " Value <br>");
  6.  
  7.  
  8. <-- I want Hiddenfield value here how can I access from ascx.cs page-->
  9. }

Demo.ascx code :
Expand|Select|Wrap|Line Numbers
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Demo.ascx.cs" Inherits="Demo" %>
  2. <asp:HiddenField ID="hidden1" runat="server"/>


Demo.ascx.cs
Expand|Select|Wrap|Line Numbers
  1. public String TextPropertuy
  2. {
  3.   get
  4.   {
  5.     return hidden1.Value;
  6.   }
  7.   set
  8.   {
  9.     hidden1.Value = value;
  10.   }
  11.  
  12. protected void Page_Load(object sender, EventArgs e)
  13. {
  14.   if (!IsPostBack)
  15.   {  
  16.      hidden1.Value = "2255";
  17.   }
  18. }
Sep 28 '11 #1
5 14910
Frinavale
9,735 Expert Mod 8TB
Why can't you just access the public property that exposes the HiddenField value?

You should not be using Response.Write in your C# code.
You should only use it in your ASP code where you want the value written to. If you use Response.Write in your C# code it will make your page's HTML invalid.

Use a Label or a Literal instead...put a Label or Literal on the aspx page and then set this Label or Literal's Text property to the value of the hidden field.

-Frinny
Sep 28 '11 #2
ma966
2
It's not getting value.. I used Label control where I want Hidden field value and I assign it, But not getting value... I wrote code like this.. in Check.aspx.cs page
Instead of "Response.Write() I used Label..." i.e.
Label1.text=hide.value; But not getting any output, Will u give me another solution for this...
Thanks.....
Sep 29 '11 #3
Frinavale
9,735 Expert Mod 8TB
Oh I see what you're doing wrong now!

You're dynamically adding the control...but you're doing it at the wrong stage in the ASP.NET life cycle. You can't do this in the Page Load event.

You need to move this to your Page Init event.
In the Page Init event the controls are initialized....right after this event, and before the Page Load event, the input on the page is loaded into the controls (that were initialized). If your control doesn't exist at this stage, then the input is not loaded!

Check out this article on How to Use dynamic Controls in ASP.NET.

If you are new to ASP.NET, you should consider just putting the user control into the page itself and avoid dynamically loading controls.

-Frinny
Sep 29 '11 #4
ma966
2
Will you please explain me this via code..... In my given code you change it, then reply mje , It's urgent please help me...
Sep 30 '11 #5
Frinavale
9,735 Expert Mod 8TB
Well, you have added the Demo user control to the Check.aspx page already...it has the ID "Hide".

This means that "Hide" (which is a Demo user control) is part of the Check page so you can access it in the Check page.

The Demo user control has a property named "TextPropertuy" (which is misspelled but that doesn't matter). You can call the TextPropertuy property anywhere in the life cycle of the Check page.

For example, you can get the value of the hidden field in the Check Page's Load event through the TextPropertuy Property in order to set the Text property of a Label control with the ID "myLabel" like this:

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.    myLabel.Text = Hide.TextPropertuy;
  4. }
Notice how I did not use the LoadControl method?
That's because the control that contains the value is already part of the page. The LoadControl method is only used to dynamically add user controls to the page...which you aren't doing.

-Frinny
Sep 30 '11 #6

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

Similar topics

0
by: dh | last post by:
As a simple example, I can't seem to be able to reference a label called "lblOutput" that exists in my test.aspx page from within a User control, TestControl.ascx. I am stumped. Any help is...
0
by: dotnet | last post by:
I am trying to make a page that is changing the page schema(colors and graphics) depends on the specific value (for example, test.aspx?page=1) I have so far achieved accepting page values (with...
3
by: Tom | last post by:
Hi, I have an index.aspx page which includes top.aspx, left.aspx, main.aspx and bottom.aspx. In the left.aspx, there is a login web control - login.ascx. It keeps session of username and role...
4
by: William LaMartin | last post by:
Is there a way to place an aspx page on a panel contained on another aspx page? I can display an HTML page on the panel using a literal can figure no way to put and aspx page there.
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
1
by: Christian Blackburn | last post by:
Hi Gang, I have trouble getting my single page Aspx pages to allow the imports and or inherits command. Can someone reply with an example. Thanks, Christian Blackburn
5
by: Fernando Chilvarguer | last post by:
I'm sure this has come up before but I could not find any post on it. How can I read a variable or property that has been set on a ASPX page from inside a ASCX control. ASPX code: public...
1
by: Ann | last post by:
i have a usercontrol with a textbox "YearOfRefTextBox" ..now after registering the usercontrol in aspx,i need to get the value of textbox in aspx thru javascript.. i did like this..but getting...
6
by: DAnDA | last post by:
Hi how can i access value of a TextBox inside ASPX Page ,,,from ASCX(User Control page) ,,,thats all.!!! Thanks
1
by: ismailc | last post by:
Good day, Need to connect & retrieve from SQL DB in aspx page. I don't know aspx & only want to edit the page to sow additional information. Can you please help by providing some code? ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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,...

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.