Showing posts with label textboxes. Show all posts
Showing posts with label textboxes. Show all posts

Monday, March 26, 2012

Set defualt date as Week Day before Today.

VB.Net and a simple aspx.net page.

I have this simple code that puts Today's date in these 2 textboxes. Can
some one tell me how to set these two boxes with yesterday's date excluding
weekends?

Thanks!
phil

----------

Dim dtmToday As String

dtmToday = Now.Date.ToString("MM/d/yyy")

TextBox1.Text = dtmToday

TextBox2.Text = dtmTodayThanks, but that didn't work. Your code just took the date back 7 days
INCLUDING WEEKENDS. If the textbox is 12/11/06, it is now 12/4/06. If I
change the code to -1, it will go back one day but it does not disregard the
weekends. How do you disregard the weekends?

"Saubz" <saubz@.newsgroups.nospamwrote in message
news:6FC8AB4E-D0BB-4843-BE0C-3EAB4E576AC7@.microsoft.com...

Quote:

Originally Posted by

Phillip,
>
Try this out
>
>
TextBox1.Text = DateAdd(DateInterval.Day, -7, DateTime.Now)
>
>
>
"Phillip Vong" wrote:
>

Quote:

Originally Posted by

>VB.Net and a simple aspx.net page.
>>
>I have this simple code that puts Today's date in these 2 textboxes. Can
>some one tell me how to set these two boxes with yesterday's date
>excluding
>weekends?
>>
>Thanks!
>phil
>>
>----------
>>
>>
>>
>Dim dtmToday As String
>>
>dtmToday = Now.Date.ToString("MM/d/yyy")
>>
>TextBox1.Text = dtmToday
>>
>TextBox2.Text = dtmToday
>>
>>
>>


On Mon, 11 Dec 2006 18:18:00 -0500, Phillip Vong wrote:

Quote:

Originally Posted by

Thanks, but that didn't work. Your code just took the date back 7 days
INCLUDING WEEKENDS. If the textbox is 12/11/06, it is now 12/4/06. If I
change the code to -1, it will go back one day but it does not disregard the
weekends. How do you disregard the weekends?


Hey Philip,

Try this out. Its not pretty but it works

sub Main
' This should return monday the 11th
Console.WriteLine( _
GetLastBusinessDay(new DateTime(2006,12,12),1))
'This should return friday the 8th
Console.WriteLine( _
GetLastBusinessDay(new DateTime(2006,12,12),2))
Console.ReadLine()
end sub

function GetLastBusinessDay (theDate as DateTime, daysAgo as Integer) as
DateTime
'
' Some local variables
'
dim counter as integer
dim temp as DateTime =theDate
'
' Put in a loop
'
while true
'
' Do some error checking
'
if theDate=DateTime.MinValue
return DateTime.MinValue
end if

'
' Decrement the day
'
temp= temp.AddDays(-1)
'
' Check if it is a weekday
'
select case temp.DayOfWeek
case DayOfWeek.Monday to DayOfWeek.Friday
'
' It is! Increment the counter
'
counter=counter+1
end select
'
' Now check if the counter is equal to
' the days we want
'
if counter=daysago then
return temp
end if

end while
end function
--
Bits.Bytes
http://bytes.thinkersroom.com

Set Focus

How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
I have several textboxes on a web form and I want to set the focus to a
specific one after the user clicks submit.

Thanks,
-CarlCarl Tribble wrote:
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl

http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx

hth

--
Craig
Microsoft MVP - ASP/ASP.NET
Here's how you set the focus to a control:
http://SteveOrr.net/faq/2in1.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Carl Tribble" <carl@.tribblesoftware.com> wrote in message
news:O7XydYjXGHA.196@.TK2MSFTNGP04.phx.gbl...
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl
Steve C. Orr [MVP, MCSD] wrote:
> Here's how you set the focus to a control:
> http://SteveOrr.net/faq/2in1.aspx

yikes! yes, steve's is the 'correct' example...my link was to one that
didn't use getElementById, which it should...sorry 'bout that...

--
Craig
Microsoft MVP - ASP/ASP.NET
Thanks to you both! I tried Steve's suggestion and it works beatifully!

"Craig Deelsnyder" <cdeelsny@.NO_SPAM_4_MEyahoo.com> wrote in message
news:O8AYsXlXGHA.2268@.TK2MSFTNGP02.phx.gbl...
> Steve C. Orr [MVP, MCSD] wrote:
>> Here's how you set the focus to a control:
>> http://SteveOrr.net/faq/2in1.aspx
>>
> yikes! yes, steve's is the 'correct' example...my link was to one that
> didn't use getElementById, which it should...sorry 'bout that...
> --
> Craig
> Microsoft MVP - ASP/ASP.NET

Set Focus

How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
I have several textboxes on a web form and I want to set the focus to a
specific one after the user clicks submit.
Thanks,
-CarlCarl Tribble wrote:
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl
>
http://ryanfarley.com/blog/archive/2004/12/21/1325.aspx
hth
Craig
Microsoft MVP - ASP/ASP.NET
Here's how you set the focus to a control:
http://SteveOrr.net/faq/2in1.aspx
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Carl Tribble" <carl@.tribblesoftware.com> wrote in message
news:O7XydYjXGHA.196@.TK2MSFTNGP04.phx.gbl...
> How do you set the focus on a web form in ASP.NET v1.1 using VB .NET 2003?
> I have several textboxes on a web form and I want to set the focus to a
> specific one after the user clicks submit.
> Thanks,
> -Carl
>
Steve C. Orr [MVP, MCSD] wrote:
> Here's how you set the focus to a control:
> http://SteveOrr.net/faq/2in1.aspx
>
yikes! yes, steve's is the 'correct' example...my link was to one that
didn't use getElementById, which it should...sorry 'bout that...
Craig
Microsoft MVP - ASP/ASP.NET
Thanks to you both! I tried Steve's suggestion and it works beatifully!
"Craig Deelsnyder" <cdeelsny@.NO_SPAM_4_MEyahoo.com> wrote in message
news:O8AYsXlXGHA.2268@.TK2MSFTNGP02.phx.gbl...
> Steve C. Orr [MVP, MCSD] wrote:
> yikes! yes, steve's is the 'correct' example...my link was to one that
> didn't use getElementById, which it should...sorry 'bout that...
> --
> Craig
> Microsoft MVP - ASP/ASP.NET

Saturday, March 24, 2012

Set focus on null fields!

Hi,
I have a login form and I have two text boxes in it and the user is required to enter data in the textboxes.If they fail to enter data in any one of the text box and hit the submit button I would like for the cursor to setfocus on the empty text box for the user to enter the data.How would I do this in asp.net.If not would I be able to write Javascript and call the function and where would I call the function.COuld someone expalin how to accomplish this.I do know how to set focus on the first textbox when the page loads up.But I am lost when I am required to setfocus the cursor at the empty text box for user entry?try this:


string strScript = null;
strScript = "<script language=javascript> document.all('TextBox1').focus() </script>";
RegisterStartupScript("focus",strScript);

HI Azam,
I am getting a synatax error. Do I have to declare strScript in my Dim?Also is this a subroutine all by itself or is it part of another subroutine(like page_load)?
Hi,

try to put this code on the Server Side Button Click event.
HI Azam,
I tried your way but I get the error message that says strString is not declared.Also in your code the "TextBox1" would be the ID for the text boxes I have in my project Right?
declare strString as a string variable.

like this:


string strString = "whatever"; // C# syntax

Yes "TextBox1" is the id for the textboxes you have in yr project.
HI Azam,
I am doing this in VB .would the codes be any different if it is VB.
Only syntax.

Here is aC# to VB.NET converter.
HI Azam,
If I did it by your codes would I be able to set focus on the null fields or just the first text box.I am so many error message and that's why I could not see the results.Could you please mail me regarding this?Thanks.
Hi Picky,
Thanks.That is a cool tool!

Set focus problem

I have a page with a drop down and several web controls. The drop down
is set to postback and it reloads the textboxes based on the selected
drop down item. I set the focus to the first textbox control on the
client like this:
<script language="vbscript">
Option Explicit
...other code
If Not <%=mbReadOnly%> Then
document.frmDetails.txtName.focus()
End If
...other code
</script>
This works fine on first page load but when I change the drop down it
does reset the focus and you can't even type in the first textbox
until you select another textbox first.
To debug I added a message box right before the set focus to see if it
was even getting to this line of code and it works but I can't leave a
message box here.
Any ideas on what could be the problem?
Thanks in advance for any help,
DeidreHi

setfocus in body onload event,

document.frmDetails.txtName.focus()

HTH
Ravikanth

>--Original Message--
>I have a page with a drop down and several web controls.
The drop down
>is set to postback and it reloads the textboxes based on
the selected
>drop down item. I set the focus to the first textbox
control on the
>client like this:
><script language="vbscript">
>Option Explicit
>...other code
>If Not <%=mbReadOnly%> Then
>document.frmDetails.txtName.focus()
>End If
>...other code
></script>
>This works fine on first page load but when I change the
drop down it
>does reset the focus and you can't even type in the
first textbox
>until you select another textbox first.
>To debug I added a message box right before the set
focus to see if it
>was even getting to this line of code and it works but I
can't leave a
>message box here.
>Any ideas on what could be the problem?
>Thanks in advance for any help,
>Deidre
>.
Thanks for the suggestion but it does the same thing if I put it in a
body onload event.

"Ravikanth[MVP]" <dvravikanth@.hotmail.com> wrote in message news:<0e1c01c34d31$17c134a0$a301280a@.phx.gbl>...
> Hi
> setfocus in body onload event,
> document.frmDetails.txtName.focus()
> HTH
> Ravikanth
I fixed my problem. I needed to move my set focus command to the window_onload sub:
Sub Window_OnLoad()
If Not <%=mbReadOnly%> Then
document.frmDetails.txtName.focus()
End If
End Sub

Deidre

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.

I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in
ASP.NET?It's a client-side task. You need to call javascript focus() method on the
element you want to set focus on.

Eliyahu

"Water Cooler v2" <wtr_clr@.yahoo.com> wrote in message
news:1124274011.476683.55980@.o13g2000cwo.googlegro ups.com...
> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
you can write a function something like this and use it when u need them.

protected void SetFocus(Control controlToFocus){
string formName = GetFormName(controlToFocus);
string jsString="<script language=javascript>document." + formName +
".elements['" + controlToFocus.UniqueID + "'].focus();</script>";
if(Page.IsStartupScriptRegistered("SetFocusToSearch")==false)
Page.RegisterStartupScript("SetFocusToSearch",jsString);

Hope this helps.
--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net

"Any one who has never made a mistake has never tried anything new" - Einstein

"Water Cooler v2" wrote:

> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
As the last post adviced this should do the trick:-

Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"

' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub

Hope this helps
Patrick

*** Sent via Developersdex http://www.developersdex.com ***

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page loads, I need the focus to be on one of the textboxes called txtUserName.

I come from a VB background, so expecting the obvious, I go to the Page_Load event of the index.aspx page and try to write txtUserName.SetFocus but I see there isn't a SetFocus method for the System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in ASP.NET?take a look at this thread:

http://www.vbforums.com/showthread.php?t=316582&highlight=textbox+focus
Hi , You may use a java script

<SCRIPT LANGUAGE="JavaScript">
function setFocus()
{
document.Form1('TxtCno').focus()
}
</SCRIPT>

and call it in

<body MS_POSITIONING="GridLayout" bgColor="#003366" onload="setFocus();">


thats it it will focus the cursor on your desired field

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.
I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.
What's the way to set the focus to a textbox on the page load in
ASP.NET?It's a client-side task. You need to call javascript focus() method on the
element you want to set focus on.
Eliyahu
"Water Cooler v2" <wtr_clr@.yahoo.com> wrote in message
news:1124274011.476683.55980@.o13g2000cwo.googlegroups.com...
> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
you can write a function something like this and use it when u need them.
protected void SetFocus(Control controlToFocus){
string formName = GetFormName(controlToFocus);
string jsString="<script language=javascript>document." + formName +
".elements['" + controlToFocus.UniqueID + "'].focus();</script>";
if(Page.IsStartupScriptRegistered("SetFocusToSearch")==false)
Page.RegisterStartupScript("SetFocusToSearch",jsString);
Hope this helps.
--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net
"Any one who has never made a mistake has never tried anything new" - Einste
in
"Water Cooler v2" wrote:

> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
As the last post adviced this should do the trick:-
Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"
' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub
Hope this helps
Patrick
*** Sent via Developersdex http://www.examnotes.net ***

Thursday, March 22, 2012

Set Focus to TextBox

I would like to set the focus to a textbox when the page first openes. I have a couple of textboxes on the form and would like the cursor to appear in the first text box when the page opens.

This is the code that I am tring to work with


<td style="WIDTH: 81px; HEIGHT: 27px" align="left">Defect:</td
<td style="WIDTH: 141px; HEIGHT: 27px">
<asp:textbox id="Defect" Runat="server" Width="304px"></asp:textbox></td>

Can anyone help me set the focus to this textbox.

Thanks.Use this JavaScript:


function SetFocusToControl(id) {
document.getElementById(id).focus();
}

In you code, just use the following code:

protected TextBox Defect;

void Page_Load(object sender, EventArgs e) {
Page.RegisterStartUpScript("focusScript", String.Format("<script language=\"JavaScript\">SetFocusToControl('{0}');</script>", Defect.ClientID));
}