Using property values of user control between two web forms.

I am stuck with a problem.
I have a user control on more than one web form( say webform1 and webform2 ).
The user control consists of several hyperlinks(say hyp1 and hyp2 ).
When I enter values in webform1 and then click 'save' button , one of the property of user control (say ID ) is assigned some value. I want to use that value 'ID' in webform2 after the user clicks on hyp2.

I dont think using Querystring will be useful because hyp1 is selected be default.
It is not a compulsion for the user, that he has to click on hyp2..he can also click on other hyperlinks of the user control also...

Please advice..

Thanks and regards,
4/29/2006 9:51:03 AM 93655 articles. 5 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 45

One option to maintain state between posts is to use a session variable.

You can store an id (or or even the usercontrol) in session when the user clicks save and then you can get the value when you arrive at webform2.aspx

On webform1:  

    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:HyperLink ID="HyperLink1" NavigateUrl="~/Webform2.aspx" runat="server">Go to webform2</asp:HyperLink>
        <asp:Button ID="btnSave" runat="server" Text="Save" />
        <uc1:myusercontrol ID="Myusercontrol1" runat="server" />
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
    Myusercontrol1.ID = Me.TextBox1.Text.Trim
    Session.Add("myuc", Myusercontrol1)
End Sub
On webofrm2:  
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     If Not IsPostBack AndAlso Session("myuc") IsNot Nothing Then
         Myusercontrol1 = CType(Session("myuc"), myusercontrol)
     End If
 End Sub

This sample just demonstrates one way of doing it. There are many ways of doing what you want to do and there are pros and cons to all of them.

Hopefully this has helped.

James Steele

4/29/2006 2:57:17 PM
Thank you soo much for your prompt reply!
It helped. Is there any other way apart from using Session variables?

Thanks and regards,


4/29/2006 3:59:08 PM

Your welcome ap. Yes there are certainly numerous other options.

This article will explain some more state management options for you like cookies, hidden fields, the viewstate, querystring, and the database. Enjoy.

State Management in ASP.NET

James Steele

4/29/2006 4:54:34 PM
Sorry to disturb you again..
Can I add the property of User control 'ID' in Session variable instead of adding the user control in session variable?? Will it work the same way as discussed above?

Thanks and regards,

4/30/2006 7:46:58 AM
Yes. That will work. Just remember when you retrieve the ID from session your will have to cast it to an integer. CType(Session("ID"),Integer)

James Steele
4/30/2006 12:15:19 PM

Similar Artilces:

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink

user control data entry form, use same codebehind as web form?
Hi All, I have a quesiton about the approach I'm taking. I have a series of report forms which I have been in the process of consolidating to a single, generic page and subs/functions in a single code-behind. All the reports can use the same set of data entry elements (a dropdown, a radio list, and a textbox). I'm trying to convert these elements to a user control. However, this user control seems to need to inherit differently than the rest of the code-behind. I've been using a single class in the code behind. Is it feasible to separate out the data entry? the code behind im...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

How to access a control on a web form from anoter web form
hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it possible to access lbl1 from form2, change its text permenantly? thanks.   refer: remember to click "Mark as Answer" on the post that helps you. MinaSamy: hi all I have this scenarios i have two web forms, one called form1 and the other called form2 form1 has a label with id "lbl1" is it p...

Accessing two web forms in a single web form
  Hi. I am developing a website in VS 2005 with Ajax & SQL Server. I am having 5 forms in my application. 1) Login Form 2) Main form 3) Form "A" 4) Form "B" I need to show the main form after the User login. I need to show all the contents of form A or form B (Ex: Form "A" user or form "B" user) in the Main Page. Can I show a single page having Main Form controls as well as Form "A" and Form "B" controls? I should access all the controls including Form A/B in the Main Page. Thanks ...

Passing Values from a Web Form to Another Web Form
Hello All! I am trying to pass values from one web form to another web form. I know that there are 3 ways of doing this: queryString, Server.Transfer and Session. I am using the Server.Transfer method. But I am not able to create, in my 2nd web form, an instance of my 1st web form. My 1st Web form is named CallTrack.aspx and my 2nd is named Export.aspx. What I mean is something like this: Public value as CallTrack. I can't create it in my 2nd web form because when the intellisense is displayed, there's no CallTrack in the options. Thanks!   How about using cross-...

can someone one give me difference between web form and mobile web form and which or where or when i'm using the forms?
thanks Marc Hi Marc, Based on my understanding, you want to know the differences between the ASP.NET web application and ASP.NET mobile web application. If I have misunderstood you, please feel free to let me know. The ASP.NET forms are used to develop the ASP.NET pages for desktop browsers and The ASP.NET mobile forms are used to develop the ASP.NET pages for mobile device browsers. When we create the ASP.NET mobile web forms pages, we can use nearly all the features of ASP.NET. But there are a couple of compatibility issues: Error Handling and Reporting. Tracing. Using Redi...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

Using Win Form controls in web forms
Hi All,   Please tell me if i can't use the window forms controls in my webform. What if i simply import the Namespace. Definitely this will help me to expose the class & methods, but will they work accordingly when get rendered. I am totally confused.. please help me. Thanks Simple answer:  You can't.  Webforms controls render as HTML; while this may be possible to achieve with Winforms controls by invoking the design-time rendering, I doubt it's going to work very well.What control are you trying to use?Peter BrunoneMS MVP, ASP.NETFounder, Easy...

Solution for web forms that look just like paper forms ? User controls ? Adobe fillable forms ?
 I am looking at ways to web-enable a series of company forms that need to have the form itself look just like the paper version.  It would be great if I could use an image of the form itself as a background, and then draw the UI components on top of this.  Then there is the question of printing these forms complete with the data that was filled in.   What are some options for doing this kind of application ?  Im open to 3rd party solutions as well.  Our company currently has a desktop application which does this, but I want to come up with a web based solu...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Web resources about - Using property values of user control between two web forms. -

Property - Wikipedia, the free encyclopedia
This article may require copy editing for grammar, style, cohesion, tone, or spelling . You can assist by editing it . In abstract, property ...

Property - Wikipedia, the free encyclopedia
In abstraction, property is that which belongs to or with something, whether as an attribute or as a component of said thing. For the significant ...

Thousands of dollars of property stolen from Port Augusta home during Christmas break-in - AdelaideNow ...
DEFENCE medals and unique jewellery are among thousands of dollars of property stolen during a break-in at a Port Augusta home over Christmas. ...

Facebook's Mark Zuckerberg faces trial over Silicon Valley property deal
... broke a promise to introduce him to Silicon Valley's elite. Facebook boss Mark Zuckerberg is headed toward a trial after all as the property ...

Canberra's rental yields on the rise, despite sluggish property market
Canberra has experienced the lowest annual shift in rental prices in Australia over the past decade.

Mount Isa Police crackdown nets 20 people over property theft - The Courier-Mail Search Search
ABOUT 20 people have been charged, including 17 juveniles, after a series of break and enters and thefts in Mount Isa.

Warning of 'unfair' process unheeded as government forges ahead with property resumptions
Private property is being forcibly resumed by the NSW government for major infrastructure projects such as WestConnex using a system it was warned ...

Property damage, power out in Waroona fire
At least one old property has been destroyed by intense fires that hit Waroona and Preston Beach. Vision courtesy of 9 News Perth.

Spiking property assessments may leave thousands without Home Owner Grant
A spike in property assessments in Metro Vancouver means thousands no longer qualify for the Home Owner Grant, unless the provincial government ...

Prestige property leads house price falls
Sydney property prices fell for the second consecutive month and the top end fell fastest, dropping 2.3 per cent in December, the CoreLogic RP ...

Resources last updated: 1/16/2016 4:41:41 PM