Hi,
I have 2 textboxes (txtVal1, txtVal2) in a WebUserControl
(WebCalcUserCon trol) for which I write public properties :
public int Value1
{
get { return Convert.ToInt32 (txtVal1.Text); }
set { txtVal1.Text = Convert.ToStrin g(value); }
}
public int Value2
{
get { return Convert.ToInt32 (txtVal2.Text); }
set { txtVal2.Text = Convert.ToStrin g(value); }
}
Then, I host the user control in a WebForm for which I provide a private
datamember in the webform :
private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol();
I add a button (btnAdd) and a Label (lblResult) to the WebForm as well.
Button Event-handler :
private void btnAdd_Click(ob ject sender, System.EventArg s e)
{
lblResult.Text = Convert.ToStrin g(
WebCalcUserCont rol1.Value1 +
WebCalcUserCont rol1.Value2);
}
I run the webapp ... enter 2 numbers in the texboxes ... press the
Add-button .. and get a run-time error : Input string was not in a correct
format.
When debugging do i notice that both Text-properties of the textboxes (of
the user control) are empty ??? (Although I entered values at run-time)
How come ?
Thanks
Chris 4 1694
If you are declaring the Web control in the ASPX form (as It looks like), then you need to change the code in the class.
instead of using:
private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol();
Code-Behind inside the Class declaration:
protected WebCalcUserCont rol WebCalcUserCont rol1; //The name you declare here, must match the ID on the ASPX page
I hope that helps...
Andrea Williams
"Chris" <ch********@pan dora.be> wrote in message news:Wz******** **************@ phobos.telenet-ops.be... Hi, I have 2 textboxes (txtVal1, txtVal2) in a WebUserControl (WebCalcUserCon trol) for which I write public properties : public int Value1 { get { return Convert.ToInt32 (txtVal1.Text); } set { txtVal1.Text = Convert.ToStrin g(value); } } public int Value2 { get { return Convert.ToInt32 (txtVal2.Text); } set { txtVal2.Text = Convert.ToStrin g(value); } } Then, I host the user control in a WebForm for which I provide a private datamember in the webform : private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol(); I add a button (btnAdd) and a Label (lblResult) to the WebForm as well. Button Event-handler : private void btnAdd_Click(ob ject sender, System.EventArg s e) { lblResult.Text = Convert.ToStrin g( WebCalcUserCont rol1.Value1 + WebCalcUserCont rol1.Value2); } I run the webapp ... enter 2 numbers in the texboxes ... press the Add-button .. and get a run-time error : Input string was not in a correct format. When debugging do i notice that both Text-properties of the textboxes (of the user control) are empty ??? (Although I entered values at run-time) How come ? Thanks Chris
Indeed !
Thanks a lot !
Chris
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:eF******** *****@TK2MSFTNG P11.phx.gbl...
If you are declaring the Web control in the ASPX form (as It looks like), then you need to change the code in the class.
instead of using:
private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol();
Code-Behind inside the Class declaration:
protected WebCalcUserCont rol WebCalcUserCont rol1; //The name you declare here, must match the ID on the ASPX page
I hope that helps...
Andrea Williams
"Chris" <ch********@pan dora.be> wrote in message news:Wz******** **************@ phobos.telenet-ops.be... Hi, I have 2 textboxes (txtVal1, txtVal2) in a WebUserControl (WebCalcUserCon trol) for which I write public properties : public int Value1 { get { return Convert.ToInt32 (txtVal1.Text); } set { txtVal1.Text = Convert.ToStrin g(value); } } public int Value2 { get { return Convert.ToInt32 (txtVal2.Text); } set { txtVal2.Text = Convert.ToStrin g(value); } } Then, I host the user control in a WebForm for which I provide a private datamember in the webform : private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol(); I add a button (btnAdd) and a Label (lblResult) to the WebForm as well. Button Event-handler : private void btnAdd_Click(ob ject sender, System.EventArg s e) { lblResult.Text = Convert.ToStrin g( WebCalcUserCont rol1.Value1 + WebCalcUserCont rol1.Value2); } I run the webapp ... enter 2 numbers in the texboxes ... press the Add-button .. and get a run-time error : Input string was not in a correct format. When debugging do i notice that both Text-properties of the textboxes (of the user control) are empty ??? (Although I entered values at run-time) How come ? Thanks Chris
but why does it have to be protected ?
using it as 'private' creates a runtime error ? ==> Object reference not set to an instance of an object.
Chris
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:eF******** *****@TK2MSFTNG P11.phx.gbl...
If you are declaring the Web control in the ASPX form (as It looks like), then you need to change the code in the class.
instead of using:
private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol();
Code-Behind inside the Class declaration:
protected WebCalcUserCont rol WebCalcUserCont rol1; //The name you declare here, must match the ID on the ASPX page
I hope that helps...
Andrea Williams
"Chris" <ch********@pan dora.be> wrote in message news:Wz******** **************@ phobos.telenet-ops.be... Hi, I have 2 textboxes (txtVal1, txtVal2) in a WebUserControl (WebCalcUserCon trol) for which I write public properties : public int Value1 { get { return Convert.ToInt32 (txtVal1.Text); } set { txtVal1.Text = Convert.ToStrin g(value); } } public int Value2 { get { return Convert.ToInt32 (txtVal2.Text); } set { txtVal2.Text = Convert.ToStrin g(value); } } Then, I host the user control in a WebForm for which I provide a private datamember in the webform : private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol(); I add a button (btnAdd) and a Label (lblResult) to the WebForm as well. Button Event-handler : private void btnAdd_Click(ob ject sender, System.EventArg s e) { lblResult.Text = Convert.ToStrin g( WebCalcUserCont rol1.Value1 + WebCalcUserCont rol1.Value2); } I run the webapp ... enter 2 numbers in the texboxes ... press the Add-button .. and get a run-time error : Input string was not in a correct format. When debugging do i notice that both Text-properties of the textboxes (of the user control) are empty ??? (Although I entered values at run-time) How come ? Thanks Chris
When you use the protected keyword, then it allows the code-behind to connect to the controls and/or code that is declares in the ASPX page. Any variable that you would want to display in the ASPX page would also need to be protected.
For example:
in Code-behind:
protected string mstrPageTitle;
public void Page_Load()
{
mstrPageTitle = "This is my Title";
}
in ASPX page:
<%=mstrPageTitl e%>
In order for the line above to work, it must be a protected variable. I guess you could say that the protected key word allows the code-behind to interact with the variables and objects. If they are private, they are private to the class only and are not shared with the ASPX.
I don't know how clear this is, so let me know if you still have questions. If someone else would like to elaborate more thoroughly, be my guest.
Andrea
"Chris" <ch********@pan dora.be> wrote in message news:EP******** **************@ phobos.telenet-ops.be...
but why does it have to be protected ?
using it as 'private' creates a runtime error ? ==> Object reference not set to an instance of an object.
Chris
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message news:eF******** *****@TK2MSFTNG P11.phx.gbl...
If you are declaring the Web control in the ASPX form (as It looks like), then you need to change the code in the class.
instead of using:
private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol();
Code-Behind inside the Class declaration:
protected WebCalcUserCont rol WebCalcUserCont rol1; //The name you declare here, must match the ID on the ASPX page
I hope that helps...
Andrea Williams
"Chris" <ch********@pan dora.be> wrote in message news:Wz******** **************@ phobos.telenet-ops.be... Hi, I have 2 textboxes (txtVal1, txtVal2) in a WebUserControl (WebCalcUserCon trol) for which I write public properties : public int Value1 { get { return Convert.ToInt32 (txtVal1.Text); } set { txtVal1.Text = Convert.ToStrin g(value); } } public int Value2 { get { return Convert.ToInt32 (txtVal2.Text); } set { txtVal2.Text = Convert.ToStrin g(value); } } Then, I host the user control in a WebForm for which I provide a private datamember in the webform : private WebCalcUserCont rol WebCalcUserCont rol1 = new WebCalcUserCont rol(); I add a button (btnAdd) and a Label (lblResult) to the WebForm as well. Button Event-handler : private void btnAdd_Click(ob ject sender, System.EventArg s e) { lblResult.Text = Convert.ToStrin g( WebCalcUserCont rol1.Value1 + WebCalcUserCont rol1.Value2); } I run the webapp ... enter 2 numbers in the texboxes ... press the Add-button .. and get a run-time error : Input string was not in a correct format. When debugging do i notice that both Text-properties of the textboxes (of the user control) are empty ??? (Although I entered values at run-time) How come ? Thanks Chris This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christian |
last post by:
Hi,
I try to change the position of a WebUserControl on my WEbform (layout is
set to GridLayout) by changing the absolute position in the html-code but it
does not work.
When I change the position at design-time for my user control by changing it
directly in html-code is the change reflected in the design view (and
vice-versa). But when I run the app is the control always positioned at the
same location (somewhere topleft on the page)
|
by: Mike Levin |
last post by:
Hello Group,
I'm using VisualStudio.NET and put a DataGrid into a WebUserControl (an ascx
file). For the DataGrid element, I have set AllowSorting="True" and
OnSortCommand="Grid_Sort".
|
by: DichkoSoft |
last post by:
Hi
I create WebUserControl and very confused when use control
For Example:
*****************************
*wuc.ascx
*****************************
<script id=clientEventHandlersJS language=javascript>
|
by: Christian H |
last post by:
Hello,
I've just created a WebUserControl that consists of a few other controls
such as DropDownList, TextBox and Button.
Based on the information entered in the DropDownlist, and TextBox, the
Button.onClick event quries a database, and returns a DataTable.
Because I'm going to use this control different places, and bind the
DataTable in different ways (sometimes a datagrid, sometimes repeater) , I
added a delegate...
|
by: Oren |
last post by:
hi,
How can I call to a Function/Property and send data dynamically to the
UserControl ? I mean Instead (look at CurrentPage):
<Result:Header id="rh" CurrentPage="1" RecordsPerPage="2" runat="server" />
To do:
<Result:Header id="rh" CurrentPage="GetText()" RecordsPerPage="2"
runat="server" />
GetText() -> on the Webform...
| |
by: Oren |
last post by:
Hi everyone,
I have WebUserControl on a Webform.
How can I sent dynamically to the WebUserControl from a Function/Property on
the Webform ?
<uc:myuc id="myid1" CurrentPage=<%#GetText()%> data="2" runat="server"/>
.....
GetText()-> function/property on the Webform, returns string and send it to
the WebUserControl -> <%#GetText()%>
|
by: Giovanni |
last post by:
Dear Friends,
I have a decision to make and hope to get some insight: I have built
several WebUserControls one of which is a WebUserControl that queries an SQL
server database, retrieves a filename and loads an image control. The
WebUserControl itself contains an SQLDataSource and an image box. I also
have other WebUserControls that implement the same concept as previously
mentioned.
The SQLDataSource is bound to a session variable...
|
by: Klaus Jensen |
last post by:
Hi
In a repeater-control, in the <SeparatorTemplatei have placed a
webusercontrol, I have made. That works great-
However, I want to know be able to only display this WebUserControl a
certain number of times. Basicly I need the WebUserControl itself to know,
how many other instances of the webusercontrol was displayed on the page,
when I run it.
|
by: deeparengan |
last post by:
hi
in asp.net i have a webusercontrol that has three dropdownlist.In the first dropdownlist i loaded the data at design time and in second dropdownlist i load the some data at run time according to the selected value in first drop downlist and in the third i loaded the values none,and,or. I want coding to display same webusercontrol while i click the values and,or in third dropdownlist placed in webusercontrol.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |