Hello Everyone, I created a custom control. On the
CreateChildCont rols, I added a textbox to the control as follows:
// TextBox
TextBox txtValue = new TextBox();
txtValue.ID = "txtValue";
protected override void CreateChildCont rols()
{
// Add the control to the form
Controls.Add(tx tValue);
}
Now during postback, I am trying to access the value of the control:
// Property inside custom control that is being called from the
webform
public bool isValidMatch()
{
if (txtValue.Text == "test")
{
return true;
}
else
{
return false;
}
}
The isValidMatch method is being called from the webform during
postback. However the value of the textbox is blank no matter what
the user enters in the webform. I must be missing something in the
postback logic configuration of custom controls but cannot figure out
what the problem is and why is the textbox value always blank.
Thanks Before Hand,
Adiel 7 3089
You might want to check into creating a custom class and use the
IPostBackDataHa ndler interface. I use something simliar for an int
value normally in drop downs...
You can have a property on the control like:
public int PostedValue
{
get { return postedValue; }
}
private int postedValue = -1;
Your interface methods might look something like:
bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
{
int presentValue = SelectedIndex;
postedValue = int.Parse(postC ollection[postDataKey]);
if (!presentValue. Equals(postedVa lue))
{
return true;
}
return false;
}
void IPostBackDataHa ndler.RaisePost DataChangedEven t()
{
OnSelectedIndex Changed(EventAr gs.Empty);
}
I'm sure this can point you in a direction at least
On Sep 17, 9:13*am, adie...@hotmail .com wrote:
Hello Everyone, I created a custom control. *On the
CreateChildCont rols, I added a textbox to the control as follows:
*// TextBox
TextBox txtValue = new TextBox();
txtValue.ID = "txtValue";
protected override void CreateChildCont rols()
* * * * {
* * * * * * // Add the control to the form
* * * * * * Controls.Add(tx tValue);
* * * * }
Now during postback, I am trying to access the value of the control:
// Property inside custom control that is being called from the
webform
public bool isValidMatch()
* * * * {
* * * * * * if (txtValue.Text == "test")
* * * * * * {
* * * * * * * * return true;
* * * * * * }
* * * * * * else
* * * * * * {
* * * * * * * * return false;
* * * * * * }
* * * * }
The isValidMatch method is being called from the webform during
postback. *However the value of the textbox is blank no matter what
the user enters in the webform. *I must be missing something in the
postback logic configuration of custom controls but cannot figure out
what the problem is and why is the textbox value always blank.
Thanks Before Hand,
Adiel
Thank you for your help. This is what I have done now. I have added
the two methods you mentioned to the custom control:
bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
{
//int presentValue = SelectedIndex;
string postedValue = postCollection[postDataKey];
//if (!presentValue. Equals(postedVa lue))
//{
// return true;
//}
return false;
}
void IPostBackDataHa ndler.RaisePost DataChangedEven t()
{
//OnSelectedIndex Changed(EventAr gs.Empty);
}
I then set a breakpoint on both methods and ran the test webform.
When I hit submit on the test webform, none of the two methods above
where called. It looks like I must still be missing something?
Thanks Again,
Adiel
Sorry meant to reply to post not just you...
Would you post what I sent you?
Thanks
On Sep 17, 12:21*pm, adie...@hotmail .com wrote:
Thank you for your help. *This is what I have done now. *I have added
the two methods you mentioned to the custom control:
* * * * bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
* * * * {
* * * * * * //int presentValue = SelectedIndex;
* * * * * * string postedValue = postCollection[postDataKey];
* * * * * * //if (!presentValue. Equals(postedVa lue))
* * * * * * //{
* * * * * * // * *return true;
* * * * * * //}
* * * * * * return false;
* * * * }
* * * * void IPostBackDataHa ndler.RaisePost DataChangedEven t()
* * * * {
* * * * * * //OnSelectedIndex Changed(EventAr gs.Empty);
* * * * }
I then set a breakpoint on both methods and ran the test webform.
When I hit submit on the test webform, none of the two methods above
where called. *It looks like I must still be missing something?
Thanks Again,
Adiel
Also... the comment I made about setting AutoPostBack is not
correct... when using the TextBox and the Submit you don't want to set
that otherwise the post back will happen when you leave the control...
since you want to wait for the Submit event do not set AutoPostBack
true... which should then fire the event for the text box upon submit.
Sorry bout that.
On Sep 17, 12:39*pm, Harv <harve...@gmail .comwrote:
Sorry meant to reply to post not just you...
Would you post what I sent you?
Thanks
On Sep 17, 12:21*pm, adie...@hotmail .com wrote:
Thank you for your help. *This is what I have done now. *I have added
the two methods you mentioned to the custom control:
* * * * bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
* * * * {
* * * * * * //int presentValue = SelectedIndex;
* * * * * * string postedValue = postCollection[postDataKey];
* * * * * * //if (!presentValue. Equals(postedVa lue))
* * * * * * //{
* * * * * * // * *return true;
* * * * * * //}
* * * * * * return false;
* * * * }
* * * * void IPostBackDataHa ndler.RaisePost DataChangedEven t()
* * * * {
* * * * * * //OnSelectedIndex Changed(EventAr gs.Empty);
* * * * }
I then set a breakpoint on both methods and ran the test webform.
When I hit submit on the test webform, none of the two methods above
where called. *It looks like I must still be missing something?
Thanks Again,
Adiel- Hide quoted text -
- Show quoted text -
Not sure if he will post so I will just put basically what I said in
case someone else has this problem.
void IPostBackDataHa ndler.RaisePost DataChangedEven t()
{
//OnSelectedIndex Changed(EventAr gs.Empty);
}
Needs to be
void IPostBackDataHa ndler.RaisePost DataChangedEven t()
{
OnTextChanged(E ventArgs.Empty) ;
}
And of course the TextChanged event will need to be implemented where
ever you have the control.
On Sep 17, 12:43*pm, Harv <harve...@gmail .comwrote:
Also... the comment I made about setting AutoPostBack is not
correct... when using the TextBox and the Submit you don't want to set
that otherwise the post back will happen when you leave the control...
since you want to wait for the Submit event do not set AutoPostBack
true... which should then fire the event for the text box upon submit.
Sorry bout that.
On Sep 17, 12:39*pm, Harv <harve...@gmail .comwrote:
Sorry meant to reply to post not just you...
Would you post what I sent you?
Thanks
On Sep 17, 12:21*pm, adie...@hotmail .com wrote:
Thank you for your help. *This is what I have done now. *I have added
the two methods you mentioned to the custom control:
* * * * bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
* * * * {
* * * * * * //int presentValue = SelectedIndex;
* * * * * * string postedValue = postCollection[postDataKey];
* * * * * * //if (!presentValue. Equals(postedVa lue))
* * * * * * //{
* * * * * * // * *return true;
* * * * * * //}
* * * * * * return false;
* * * * }
* * * * void IPostBackDataHa ndler.RaisePost DataChangedEven t()
* * * * {
* * * * * * //OnSelectedIndex Changed(EventAr gs.Empty);
* * * * }
I then set a breakpoint on both methods and ran the test webform.
When I hit submit on the test webform, none of the two methods above
where called. *It looks like I must still be missing something?
Thanks Again,
Adiel- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Thanks Harv, here is an update:
I added this to the custom control:
void IPostBackDataHa ndler.RaisePost DataChangedEven t()
{
OnTextChanged(E ventArgs.Empty) ;
}
Then I receive an error "The name 'OnTextChanged' does not exist in
the current context.
Thanks,
Adiel
Your class looks something like:
public class SomeTextBox : System.Web.UI.W ebControls.Text Box,
System.Web.UI.I PostBackDataHan dler
{
public string PostedValue
{
get { return postedValue; }
}
private string postedValue = string.Empty;
public SomeTextBox() { }
bool IPostBackDataHa ndler.LoadPostD ata(string postDataKey,
System.Collecti ons.Specialized .NameValueColle ction postCollection)
{
string presentValue = this.Text;
postedValue = postCollection[postDataKey];
if (!presentValue. Equals(postedVa lue))
{
return true;
}
return false;
}
void IPostBackDataHa ndler.RaisePost DataChangedEven t()
{
OnTextChanged(E ventArgs.Empty) ;
}
}
Make sure you have all your references of course if you are using the
"using" instead of spelling out the path...
On Sep 18, 8:02*am, adie...@hotmail .com wrote:
Thanks Harv, here is an update:
I added this to the custom control:
* * * * void IPostBackDataHa ndler.RaisePost DataChangedEven t()
* * * * {
* * * * * * OnTextChanged(E ventArgs.Empty) ;
* * * * }
Then I receive an error "The name 'OnTextChanged' does not exist in
the current context.
Thanks,
Adiel
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ashish |
last post by:
Hi All,
I have a server runnable textbox control. I also have a server side button
object but I hook up javascript to it to show a modal dialog. Upon return it
places the value in the textbox (client side script). The problem is that
after it places the value, postback occurs and value is lost. I have tried
overriding SaveViewState and LoadViewState but it doesnt help (for some
super cool reason load is called first after postback rather...
|
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);
}
|
by: guoqi zheng |
last post by:
Dear sir,
I have a textbox inside a repeart control, autopostback set to true for that
textbox. When the value of this textbox changes, I need to access current
row and update database.
Repeater is bind to a dataset. VS.NET generate a below event on double click.
However, I did not see any way to access current row.
Public Sub TxtQuantity_TextChanged(ByVal sender As Object, ByVal e As System.
|
by: Sanjay Pais |
last post by:
I built a custom control for all the basic web.ui.controls like textbox,
label, checkbox etc etc. I added my custom attribute called ApplySecurity to
the html in the page.
However, when I cycle through the controls on the page using this code, I
cant seem to be able to access the Attribute collection. However, if I were
to add the tag to a regular TextBox, the Attribute is available.
My recursive function looks like this:...
|
by: datakix |
last post by:
After 16 hours of frustration, I've managed to solve this problem for a
project I'm working on.
The 'trick' is set EnableViewState="False" for the asp:textbox inside
the Repeater control.
The problem is that by default the asp:textbox ViewState is True. This
means that the textbox value is automatically preserved between
postback (saved in the __VIEWSTATE hidden field and restored during a
page postback).
| |
by: Paul |
last post by:
Hi all,
I have a simple custom control with a label and a text box. The text
control's value is persisting when I do a post back, so the view state
is working, but I cannot access the value in the code. Is there
anything different I have to do to expose the value of the text box?
testControl.Text returns the unchanged original value, not the new
value.
|
by: paulcis |
last post by:
I am trying to produce a dynamic form from a database with unknown
amount of records.
I need to read the values and create a new textbox for each.
I need to create the textboxes at page_init stage as indicated by
microsoft.
But I can't seem to save the number of controls in a viewstate
variable or a session variable
when creating them in page_init .
see code below
|
by: Andy B |
last post by:
I have a class I am creating for data access. I need to access controls from
inside the class that are on a particular page. How do I do this? or is
creating an instance of the page class and using FindControl the only way to
do it?
|
by: =?Utf-8?B?RHlsYW5TbWl0aA==?= |
last post by:
I have a WebForm where I'm dynamically creating some controls and I'm having
difficulty understanding how the state is being persisted and how to work
with it.
I've created a simplified example to demonstrate my issues. Lets say I have
a WebForm with a DropDownList where the user selects a number from 1 to 10
(the DropDownList is not dynamically created). I also have a button on there
that I use to trigger a PostBack.
Based on the...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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: 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...
|
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: 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: 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.
| |
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...
| |