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

How to get a User Control's Property from a .aspx (Codebehind code

Hi there, I really need your help on this. I'm trying to learn to using the
VS.2003 to create a User Control. In my aspx code has no problem to use the
property "grossWaye" that has "register" in the aspx code if I don't use
"Codebehind" directive. If I try to move the <script></script> coding the
Codebehind of the VS2003. I don't know how to get the property "grossWaye". I
post both User Control and .aspx codes for your help. Thanks in advance!

User Control(UserControlPayroll.ascx):
aspx code:

namespace MyDotNet.UserControl
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for UserContriolPayroll.
/// </summary>
public class UserContriolPayroll : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox txtH;
protected System.Web.UI.WebControls.TextBox txtR;
protected System.Web.UI.WebControls.Button btnCompute;
protected System.Web.UI.WebControls.Label lblPayMsg;
protected System.Web.UI.WebControls.Label lblPay;
protected System.Web.UI.WebControls.Label lblTitle;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public string Title
{
get
{
return lblTitle.Text;
}
set
{
lblTitle.Text = value;
}
}

private double grWage;

public double grossWage
{
get
{
return double.Parse(lblPay.Text);
}
}

protected void companyPay(object obj, EventArgs e)
{
double h, r, g;
h = double.Parse(txtH.Text);
r =double.Parse(txtR.Text);
lblPayMsg.Text = "Your Gross Wag is:";

g = h * r;

lblPay.Text = g.ToString();

grWage = g;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
========================
aspx file to use abvoe Control(UsingUserControlPayroll.aspx):
1) aspx code: %@ Page language="c#"
Codebehind="UsingUserControlPayroll.aspx.cs" AutoEventWireup="false"
Inherits="MyDotNet.UserControl.UserControlPayroll" %>
<%@ Register TagPrefix="userCtrlPayroll" TagName="payroll"
Src="UserControlPayroll.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Using User Control Payroll</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
Hello there, here we are in our main page. Now, let us instantaite the
payroll
user control<br>
<userctrlpayroll:payroll id="usrPayCtrl" title="Concord Idea"
runat="server"></userctrlpayroll:payroll><br>
<asp:button id="btnShowTax" style="Z-INDEX: 101; LEFT: 16px; POSITION:
absolute; TOP: 288px"
onclick="computeTax" runat="server" Text="Show
Tax"></asp:button><asp:label id="lblTaxMsg" style="Z-INDEX: 102; LEFT: 16px;
POSITION: absolute; TOP: 328px"
runat="server" Width="160px"></asp:label><asp:label id="lblTax"
style="Z-INDEX: 103; LEFT: 200px; POSITION: absolute; TOP: 328px"
runat="server"
Width="200px"></asp:label></form>
</body>
</HTML>
2) Codebehind C# code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyDotNet.UserControl
{
/// <summary>
/// Summary description for UserControlPayroll.
/// </summary>
public class UserControlPayroll : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblTaxMsg;
protected System.Web.UI.WebControls.Label lblTax;
protected System.Web.UI.WebControls.Button btnShowTax;

private void Page_Load(object obj, System.EventArgs e)
{
// Put user code to initialize the page here

}

protected void computeTax(object obj, System.EventArgs e)
{
double t, gWage;
gWage = usrPayCtrl.grossWage;
t = gWage * 0.10;

lblTaxMsg.Text = "Your Tax is :";
lblTax.Text = t.ToString("c");
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

}

}
--
Colin
Nov 22 '05 #1
0 1906

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

Similar topics

0
by: Amir Eshterayeh | last post by:
Dear Friends Hope things goes well to you. I have this problem. Would you please give me your solution? I want to change a property that I define on my user control in my web form that contains...
0
by: Colin | last post by:
Hi there, I really need your help on this. I'm trying to learn to using the VS.2003 to create a User Control. In my aspx code has no problem to use the property "grossWaye" that has "register" in...
2
by: adiel | last post by:
Hello, I am trying to access the properties and methods from a user control within the code-behind file for a webform but I am receiving the message: Name 'MenuBar1' is not declared It does...
6
by: Nehal Shah | last post by:
I've read that in the Page Directive of an aspx page, changing the CodeBehind attribute to Src saves you from having to compile the page before refreshing. This is preferable in a large...
1
by: Kris van der Mast | last post by:
Hi, been a while since I posted a question myself instead of trying to help others out. I'm refactoring an existing web app that uses dynamic loading of user controls and a lot of...
12
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
5
by: c676228 | last post by:
Hi, I guess I am confused. In aspx script, I mean (you won't use Codebehind="enrollinfo.aspx.vb", but mix code with html and code together) You can access user control's property directly. Since I...
2
by: | last post by:
I want to use codebehind to pass property values to a control that I've embedded INSIDE of a user control. In other words, let's say I have the following: MyPage.aspx ....with the following...
4
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.