473,725 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UserControl and sending/getting information from it

Hello Group,

I have created an ASP.NET page. The page consist of the following items:
- Button A
- Button B
- UserControl

When I press Button A, I execute the following code:
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";

When I press Button B, I execute the following code:
ViewState["pdbmode"] = "create";
Session["pdbmode"] = "create";

In my UserControl PageLoad() I have the following code:
if (ViewState["pdbmode"] == null)
Label1.Text = "Null";
else if(ViewState["pdbmode"] == "edit")
Label1.Text = "Edit";
else if(ViewState["pdbmode"] == "create")
Label1.Text = "Create";
else
Label1.Text = "Unknown";

if (Session["pdbmode"] == null)
Label2.Text = "Null";
else if(Session["pdbmode"] == "edit")
Label2.Text = "Edit";
else if(Session["pdbmode"] == "create")
Label2.Text = "Create";
else
Label2.Text = "Unknown";

---

The problem is that when I press Button A, Label1 which uses ViewState never
changes away from being Null.
Label2 Changes, but I it changes too late. I press Button A, Label2 stays
"null", then I press Button A and it changes to edit.

I guess I need to do this completly different, but how?

Basically I just need my UserControl to know if ButtonA was pressed, or
ButtonB was pressed.

I hope someone can help me, please :)
- Cederström
Nov 18 '05 #1
2 1353
The Page Load for a control is always before the control is handed over to
Event execution....

so what is happening is that you are executing a check on your
ViewState["pdbmode"] for null and assigning it always and then

when Button A . click event is called

you assign view state... and session...
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";

once you are out... the render is called and it renders....

put the check for checking viewstate and session and to assign label values
in a seperate method call....
CheckAndLoad()
{
if (ViewState["pdbmode"] == null)
Label1.Text = "Null";
else if(ViewState["pdbmode"] == "edit")
Label1.Text = "Edit";
else if(ViewState["pdbmode"] == "create")
Label1.Text = "Create";
else
Label1.Text = "Unknown";

if (Session["pdbmode"] == null)
Label2.Text = "Null";
else if(Session["pdbmode"] == "edit")
Label2.Text = "Edit";
else if(Session["pdbmode"] == "create")
Label2.Text = "Create";
else
Label2.Text = "Unknown";
}

on Page load first check to see if its a post back... if not then you call
the method to check view state and session and assign label text
if(!Page.IsPost back)
{
CheckAndLoad();
}

from you Event handler say Button A click
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";
CheckAndLoad();

assign values... and then call the method to check viewstate and session and
assign the values to you label.

--
Regards,

HD

"Cederstrom " <lasse#Remove#@ *This*cederstro m.dk> wrote in message
news:eI******** ******@TK2MSFTN GP10.phx.gbl...
Hello Group,

I have created an ASP.NET page. The page consist of the following items:
- Button A
- Button B
- UserControl

When I press Button A, I execute the following code:
ViewState["pdbmode"] = "edit";
Session["pdbmode"] = "edit";

When I press Button B, I execute the following code:
ViewState["pdbmode"] = "create";
Session["pdbmode"] = "create";

In my UserControl PageLoad() I have the following code:
if (ViewState["pdbmode"] == null)
Label1.Text = "Null";
else if(ViewState["pdbmode"] == "edit")
Label1.Text = "Edit";
else if(ViewState["pdbmode"] == "create")
Label1.Text = "Create";
else
Label1.Text = "Unknown";

if (Session["pdbmode"] == null)
Label2.Text = "Null";
else if(Session["pdbmode"] == "edit")
Label2.Text = "Edit";
else if(Session["pdbmode"] == "create")
Label2.Text = "Create";
else
Label2.Text = "Unknown";

---

The problem is that when I press Button A, Label1 which uses ViewState never changes away from being Null.
Label2 Changes, but I it changes too late. I press Button A, Label2 stays
"null", then I press Button A and it changes to edit.

I guess I need to do this completly different, but how?

Basically I just need my UserControl to know if ButtonA was pressed, or
ButtonB was pressed.

I hope someone can help me, please :)
- Cederström

Nov 18 '05 #2
Cederstrom wrote:
The problem is that when I press Button A, Label1 which uses ViewState never
changes away from being Null.
Label2 Changes, but I it changes too late. I press Button A, Label2 stays
"null", then I press Button A and it changes to edit.

I guess I need to do this completly different, but how?

Basically I just need my UserControl to know if ButtonA was pressed, or
ButtonB was pressed.

I hope someone can help me, please :)
- Cederström


I believe the problem is that the user control has a ViewState
collection of its own, different from the Page's ViewState. To access
the ViewState you are seeking, check

this.Page.ViewS tate["pdbmode"]

and so on instead. I think that should work.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #3

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

Similar topics

4
9377
by: james | last post by:
I cannot get my UserControl's browsable properties to show up in the designer properties panel. I have then public virtual bool TestProp { {get return testProp; } set { testProp = value; } } but it doesn't show up in the designer. By the way, this used to work in the 2002 version, now in 2003 I am getting all kinds of problems like this
5
3295
by: Markus Wildgruber | last post by:
Hi! We create an inherited user control and add it to a form. When we successfully compile the project and switch to the designer of the form again, the control disappears and we get 2 error messages in the task list: There is already a component named 'dataGridControl1'. Components must have unique names, and names must be case-insensitive. A name also cannot conflict with the name of any component in an inherited class.
3
3968
by: ZhangZQ | last post by:
Supposing I have a class "UserControl1 : System.Windows.Forms.UserControl" in an Assembly "UI.dll", now I create an Application project and want to use the "UserControl1" in another AppDomain, private void CreateUIInAnotherDomain() { UI.UserControl1 ui = (UI.Cls)domain.CreateInstanceFromAndUnwrap(@".\UI.dll", "UI.UserControl1"); this.Controls.Add(ui);
9
2452
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx"); ucline.Initializecontrol(line,alternate); Placeholder1.Controls.Add(ucline); }
12
2208
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
2
3437
by: junOnline | last post by:
Hi, I am developing an asp.net 2.0 application using visual studio 2005 on my computer and I am getting very inconsistent results when I test on my computer versus from other computers. The symptom of the problem is that the web server does not receive cookie information from the browser after I have properly logged in to the web server. Without this information, my session state keeps on getting lost and the authentication logic sends...
1
4859
by: James | last post by:
CWinFormsDialog in .net 2.0 lets you host a .Net UserControl as a dialog in a managed C++ MDI application. I.e. in the sample: ----------------------------------------------- #include <afxwinforms.h> #using <WinFormUserControl1.dll> using namespace WinFormUserControl1;
3
3037
by: Jeff | last post by:
Hey ASP.NET 2.0 This the ObjectDataSource in my UserControl, <asp:ObjectDataSource ID="odsMessage" runat="server" SelectMethod="ExecuteMessage" TypeName="AH.MyNetwork.BLL.Network.Message"> <SelectParameters> <asp:ProfileParameter Name="user" PropertyName="UserName"
9
3465
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient oSMTP.Send(oMailMessage) (in this line I am getting the above err)
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4517
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.