Saturday, March 31, 2012
Text Box events
a different text box. Is this even possible? If so can someone point
me towards a good example?
Thanks,
JaimeHi Jaime,
You can diable the first Textbox whenevr you type anything in the second
textbox by using this code:
Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox2.TextChanged
Me.TextBox1.Enabled = False
End Sub
Set the AutoPostback property of the second textBox to True and as soon as
the focus from the second textbox is out, the first textbox is disbaled.
Regards,
Manish
www.ComponentOne.com
"jhcruz@.jmaweb.biz" wrote:
> I'm trying to disable one text box when a user starts entering data in
> a different text box. Is this even possible? If so can someone point
> me towards a good example?
> Thanks,
> Jaime
>
"Manish" <Manish@.discussions.microsoft.com> wrote in message
news:A6687B13-88A4-403E-BBD8-37EA92826B7A@.microsoft.com...
> You can diable the first Textbox whenevr you type anything in the second
> textbox by using this code:
> Protected Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles TextBox2.TextChanged
> Me.TextBox1.Enabled = False
> End Sub
> Set the AutoPostback property of the second textBox to True and as soon as
> the focus from the second textbox is out, the first textbox is disbaled.
The above requires a totally unnecessary roundtrip to the server and back...
<asp:TextBox ID="TextBox1" runat="server" />
<asp:TextBox ID="TextBox2" runat="server" />
private void Page_Load(object sender, System.EventArgs e)
{
TextBox1.Attributes.Add("onkeypress", "document.getElementById('" +
TextBox2.ClientID + "').disabled=\"disabled\";");
}
Mark Rae
ASP.NET MVP
http://www.markrae.net
Text box enter
Hi,
I think you are referring about handling the event for the enter key right?
In your code behind, you will find the handle event for the button click as below:-
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
End Sub
you need to add the textbox's text changed event to it as below:-
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click, TextBox1.TextChanged
End Sub
This should help you.
Thanks.
Many thanks
your welcome!
did that work for you?
thanks.
text box editing
Dim badCharReplace As Regex = New Regex("([<>""'%;()&])")
Dim s As String = badCharReplace.Replace(psInput, "")
Text Box Loses Value On Page Load
else has noticed this and b) if so, why does it happen.
On page load, I have a text box named me.txtMemberName. I enter data into
this field then submit the page. If I check the value of
me.txtMemberName.text during the page load event, it is an empty string. Now,
if I check this again in a later event, the value of .text has the correct
inforamation in it. This is causing me grief b/c, since this is a required
field, Page.IsValid is failing on page load. Any thoughts?
Thanks!
ClayFirst of all, I am assuming you have EnableViewState=True for this Control,
as well as for the Page. Second, can you post your Page.Load procedure so we
can see exactly what you do there and how you do it? This may help me and
others help you solve your problem. Thanks.
--
Nathan Sokalski
njsokalski@.hotmail.com
http://www.nathansokalski.com/
"Clayton Hoyt" <ClaytonHoyt@.discussions.microsoft.com> wrote in message
news:1D931693-325B-4116-901F-3D09CF24FE8C@.microsoft.com...
> Hi Folks...this is a wierd issue I've noticed and wanted to know of a)
> anyone
> else has noticed this and b) if so, why does it happen.
> On page load, I have a text box named me.txtMemberName. I enter data into
> this field then submit the page. If I check the value of
> me.txtMemberName.text during the page load event, it is an empty string.
> Now,
> if I check this again in a later event, the value of .text has the correct
> inforamation in it. This is causing me grief b/c, since this is a required
> field, Page.IsValid is failing on page load. Any thoughts?
> Thanks!
> Clay
Text box looping question.
There are 5 records in my table. companyid and companyname fields.
If I want to display all five records but as editable textboxes. So each textbox has the companyid from table and companyname as the text value.
Then if they hit save -- it loops through and saves all values in textboxes to the table based on the id.
Do I do put the textboxes inside a repeater?Or do I put the textboxes inside a datalist and do it that way. I'm not sure about the saving procedure.
I think you can use a repeater,
try this (this should definitely work :)):
<asp:Repeater id="myRptr" runat="server">
<ItemTemplate>
<input type=text id='<%# DataBinder.Eval(Container.DataItem, "companyid ") %>'
value='<%# DataBinder.Eval(Container.DataItem, "companyname") %>'>
</ItemTemplate>
</asp:Repeater>
It didn't like that ('<%# DataBinder.Eval(Container, "DataItem.company_id") %>' is not a valid identifier.) so I tried:
<asp:TextBox id="txtName" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.company_name") %>'></asp:TextBox>
<asp:Label ID="lblName" Runat="server" text=<%# DataBinder.Eval(Container, "DataItem.company_id") %>></asp:Label
Then in codebehind
Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next
That gives me the companyname and id. Then I can just use update statement in the [for...next] and update.
I tried this way instead and it seems to work.
<asp:TextBox id="txtName" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.company_name") %>'></asp:TextBox>
<asp:Label ID="lblName" Runat="server" text=<%# DataBinder.Eval(Container, "DataItem.company_id") %>></asp:Label
Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next
Then I just use update statement inside [for ... next]
You can use either... Repeater is a lighter control though...
All the form data will be post back (there is no looping concept)
You can read a very good MSDN article on control choice here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/aspnet-whenusedatawebcontrols.asp
Good luck :)
I used:
<asp:TextBox id="txtName" runat="server" text='<%# DataBinder.Eval(Container, "DataItem.company_name") %>'></asp:TextBox>
<asp:Label ID="lblName" Runat="server" text=<%# DataBinder.Eval(Container, "DataItem.company_id") %>></asp:Label>
Behind file
Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next
I dont know why you have to do this...
I tested this code piece before i posted it and it works fine with me I do not have to use the DirectCast and all that...
Simple '<%# DataBinder.Eval(Container, "DataItem.company_id") %>' works !!!
Did you databind the repeater to a datasource in the Page_Load ?
What does your [for ...next] loop look like?
I tried it with <asp:textbox not with a regular input box like you have. Sorry. So it will work the way you said.
I call this after I hit save to get the values:
Dim j As RepeaterItem
For Each j In rptName.Items
Response.Write(DirectCast(j.FindControl("txtName"), TextBox).Text & "<br>")
Response.Write(DirectCast(j.FindControl("lblName"), Label).Text & "<br>")
Next
How would you get the values using your way?
Oh yes... about the code behind... you will have to do the FindControl...
I am not sure why you are using 'DirectCast(j.FindControl("txtName")... ' what if you use
this.FindControl("txtName")
I might be wrong... cause I am not sure why you need the DirectCast function...
Let me know
text box misbehaviour
Hi
I have a text box which provides a parameter for a query which does a search against a database. the text will be populated on load. But if I edit the text box like say add a few letters then the search is not working. So I did the search by doing the test query feature of the wizard giving the exact parameter value ,it gave me the results. So I went back again and deleted everything upto the first first letter and manually re-entered the parameter in the textbox and searched this time I got the results. Seems like there is some hidden values in the TextBox which I have to delete manually . Has anyone come across a situation like this . Please advice how to solve this behaviour.
Thanks
How are you pre populating the textbox?
<asp:TextBox id="foo" runat="server">bla bla bla </asp:TextBox>
or
<asp:TextBox id="foo" runat="server" Text="bla bla bla" />
Note how the first way leads to a phantom space in your textbox...
I am populating it from a dataRow cell.
building1TextBox.Text = BuildingAddressTable[0].BuildingAddress;
What do you think
Thanks
hmm.
What does the Text property look like if you view it in the debugger when it is assigned to your parameter collection? Do you seen any phantom characters?
maybe something like this
building1TextBox.Text = Trim(BuildingAddressTable[0].BuildingAddress);
or
building1TextBox.Text = BuildingAddressTable[0].BuildingAddress.ToString().Trim();
not sure about the syntax - could be just .Trim()
This will trim whitespace from the beginning and end of the specified string.
Text box losing most recent Text value
the total fees the registrant will incur and puts it in a textbox (not a
label because it has to be passed to another page).
txtTotalFees.Text = Format(dblTotalFees, "Currency")
The subroutine works fine IF I call it from PageLoad, or I assign it to a
button for recalculating the total fees, or the user clicks the Reset
button, or if they click a control that has AutoPostback set to true.
Basically anything that loads or postbacks the page.
BUT...When it comes time to submit the page and go to the next page I have
this code:
If IsValid Then
CalcFees() 'recalcs fees and updates textbox
Server.Transfer("Confirmation.aspx", True)
End If
When the user gets to the next page I put the total fees in another textbox.
EXCEPT it isn't updated to most recent total. I know because I can comment
out the "Server.Transfer" so that it stays at the registration page AND THE
CORRECT TOTAL IS DISPLAYED!?!?!
What is it about the Server.Transfer that "forgets" what the value of the
textbox should be?
Ken "BiggMakk" McCroryHi Ken
Try this:
Server.Transfer("Confirmation.aspx", True)
This sets the parameter preserveForm to true, hence preserving any
variables still available.
You can then retrieve the value from your previous page on the
Confirmation.aspx page by using Request.Form("totalFees")
Hope that helps :)
sze
Thanks for the try but I am already using the True to preserve variables.
(See original post. It's there.)
Ken "BiggMakk" McCrory
"sze" <szeying.tan@.gmail.com> wrote in message
news:1110401185.776188.29550@.o13g2000cwo.googlegroups.com...
> Hi Ken
> Try this:
> Server.Transfer("Confirmation.aspx", True)
> This sets the parameter preserveForm to true, hence preserving any
> variables still available.
> You can then retrieve the value from your previous page on the
> Confirmation.aspx page by using Request.Form("totalFees")
> Hope that helps :)
> sze
>
Ah, sorry. I didn't notice it in your code at first glance.
Here's a helpful page from MSDN about preserving state between pages.
http://msdn.microsoft.com/library/d...etweenPages.asp
Hope that helps.
I solved this by using SmartNavigation and turning on Autopostback for every
control that can affect the total fees. Before someone says SmartNav doesn't
work in browsers other than IE, you're right. Someone else in a different
post of mine pointed out Smart Scroller by Strength Technologies at this web
site:
http://www.strengthtechnologies.com...l/Download.aspx
It works even in Firefox.
Now the Total fees gets updated before the user hits the Submit button and
the correct value gets passed to the next page. It also removes the need for
the manual "Recalculate Fees" button that I had on the page.
--
Ken "BiggMakk" McCrory
"Ken McCrory" <klm355t@.removefornospammers.smsu.edu> wrote in message
news:OjfvdfOJFHA.688@.TK2MSFTNGP10.phx.gbl...
> It's me and my registration page again. I have a subroutine that
> calculates the total fees the registrant will incur and puts it in a
> textbox (not a label because it has to be passed to another page).
> txtTotalFees.Text = Format(dblTotalFees, "Currency")
> The subroutine works fine IF I call it from PageLoad, or I assign it to a
> button for recalculating the total fees, or the user clicks the Reset
> button, or if they click a control that has AutoPostback set to true.
> Basically anything that loads or postbacks the page.
> BUT...When it comes time to submit the page and go to the next page I have
> this code:
> If IsValid Then
> CalcFees() 'recalcs fees and updates textbox
> Server.Transfer("Confirmation.aspx", True)
> End If
> When the user gets to the next page I put the total fees in another
> textbox. EXCEPT it isn't updated to most recent total. I know because I
> can comment out the "Server.Transfer" so that it stays at the registration
> page AND THE CORRECT TOTAL IS DISPLAYED!?!?!
> What is it about the Server.Transfer that "forgets" what the value of the
> textbox should be?
> Ken "BiggMakk" McCrory
>
Yeah Ken the control works with FireFox and I.E!!!
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!