Showing posts with label textbox. Show all posts
Showing posts with label textbox. Show all posts

Thursday, March 29, 2012

Performance related Question.....

In my ASP.Net application I am using webcontrols.TextBox to display data. I
can use the Label control to display my data here since I am using this edit
box as read only. Will there be any advantage of using label box instead of
text box in terms of memory usage or any other performance issue ? Please
advice.
CrisHi,

I don't think there are big differences between label and textbox, Both
of them are persistent accross requests.
The only difference is that the label iclude the text within <span> tags
while the textbox in the value property of the <input> tag. So there is
just a sligthly difference in the amount of byte sent to the browser.

Hope this helps

Stefano Mostarda MCP
Rome Italy
Cris Rock wrote:

> In my ASP.Net application I am using webcontrols.TextBox to display data. I
> can use the Label control to display my data here since I am using this edit
> box as read only. Will there be any advantage of using label box instead of
> text box in terms of memory usage or any other performance issue ? Please
> advice.
> Cris
>

Monday, March 26, 2012

performing error check on date values entered in a textbox

If you perform "Convert. ToDateTime" to the text of a textbox, the syntax should be yyyy-mm-dd. What is the syntax for performing a checking condition (so that I can output an error note if the values in the textbox are wrong rather than the whole server error screen appearing) such that I can check that the month doesn't exceed 12 and the day doesn't exceed 31 because a code such as: label1.text = Convert.ToDateTime(textbox1.text) would produce an error if the month exceeds 12 or the day exceeds 31. Thanks for the help.Why not use one of the Validator controls? There is a DataType check that can be applied to the CompareValidator (as I recall). I am not sure what it would do with yyyy-mm-dd (unless that is the format set up in regional settings) but in a pinch, you can do a custom validator...
Use the compareValidator, and set the Type to Date (making sure you also set the 'Control to Validate' property).

If you really really really want to do it in code (which is not advisable, but I have had to do it once or twice), then here is a little function I got from somebody:


Public Function IsDateValid(ByVal strDate As String) As Boolean
Try
' attempt parse
Dim dtParsed As DateTime = DateTime.Parse(strDate)
Return True
Catch ' parse failed
End Try
Return False
End Function

IsDateValid("200323") returns false
IsDateValid("20/12/2004") returns true

Not sure if it will work with yyyy-mm-dd, but try and and let us know.

HTH

Jagdip

perhaps a simple question

Hi,

i have a problem.

I have a textbox and a button and a link in my application. When the user clicks the button, the text of the textbox is inserted in my table northwind.
After this is done succesful i want to display a messagebox. After searching in the groups i did this.

Button1_Click(......)
{
--entry in northwind--

string alertscript= "<script language= JavaScript>alert('Succefull inserted');</script>";
if(!IsClientScriptBlockRegistered("alert"))
{
this.RegisterClientScriptBlock("alert", alertscript);
}
}

It works good. But when i click now on the link to another page and then after that click the backbutton in the IE6 to my first page, then the messageBox pops up again. I don`t know why this is done. Is the script still registered ? Please help me? I need to stop this.

Thankswhen you hit your back button, your going back to a cached copy of the page which still has the script in it.

personally, i wouldnt use an alert. Id put a Label/Literal control on the page and then upon successfully inserting a db record, you can set the Text of that control and make it visible.

When the user hits their back button, they still see the old message, but it's not in the way...

Friday, March 16, 2012

Persistent ViewState

Hello everybody!
Imagine a form with several TextBox WebControls and two buttons "New" which
should clear the form and "Save". On reloading or leaving the page which
holds the form the TextBoxes should be cleared so I've disabled the
ViewStates of these TextBoxes by setting the EnableViewState property to
false.
The method which is bound to the OnClick event of the "New" button is
empty. When clicked a PostBack occurs which, theoretically, should be
sufficient to clear the TextBoxes because their state shouldn't be saved.
Unfortunately after the PostBack the data is still there! I've had a look
into the HTML source and found out that the value property of the TextBoxes
is set, so there's still a ViewState?! Even a ViewState.Clear() and/or
ClearChildViewState() within OnClick() doesn't work!
Disabling the ViewState for the whole page is no solution because the page
also contains a DataGrid and other controls which depend on the ViewState.
Please help!
Sincerely
Sven JacobsViewState is a different state persistance mechanism than the normal <form>
post data. ViewState is for data that is not part of the normal POST. The
text in a Label is saved in ViewState because a <span> doesn't post when
the form is submitted. The text in a TExtBox will be submitted, and thus
disabling viewstate has no effect on that.
-Brock
DevelopMentor
http://staff.develop.com/ballen

> Hello everybody!
> Imagine a form with several TextBox WebControls and two buttons "New"
> which should clear the form and "Save". On reloading or leaving the
> page which holds the form the TextBoxes should be cleared so I've
> disabled the ViewStates of these TextBoxes by setting the
> EnableViewState property to false.
> The method which is bound to the OnClick event of the "New" button is
> empty. When clicked a PostBack occurs which, theoretically, should be
> sufficient to clear the TextBoxes because their state shouldn't be
> saved. Unfortunately after the PostBack the data is still there! I've
> had a look into the HTML source and found out that the value property
> of the TextBoxes is set, so there's still a ViewState?! Even a
> ViewState.Clear() and/or ClearChildViewState() within OnClick()
> doesn't work!
> Disabling the ViewState for the whole page is no solution because the
> page also contains a DataGrid and other controls which depend on the
> ViewState.
> Please help!
>
> ViewState is a different state persistance mechanism than the normal <form>
> post data. ViewState is for data that is not part of the normal POST. The
> text in a Label is saved in ViewState because a <span> doesn't post when
> the form is submitted. The text in a TExtBox will be submitted, and thus
> disabling viewstate has no effect on that.
So what you saying is that the state persistance of a form is a feature of
HTTP / the browser? How to clear the form then, via JavaScript?
Thanks!
Sincerely
Sven Jacobs
> So what you saying is that the state persistance of a form is a feature of
> HTTP / the browser? How to clear the form then, via JavaScript?
Forget that! After reading this article
http://aspalliance.com/articleViewer.aspx?aId=135 I think I now what the
difference between ViewState and PostBack data is.
So what I have to do is not to import the PostBack data on a special
condition (=New button clicked).
Sincerely
Sven Jacobs
No, the form persistance is a feature of the ASP.NET runtime, in that it
matches the control id in the POST data and fills the associated value from
that. See
http://msdn.microsoft.com/library/d...br />
tate.asp
To clear the form, loop through the controls on the form, and check if the
control is a textbox, or certain type of control, then set the value to an
empty string, or index to -1 if a droplist etc. It really depends on what
type of control you are working with as there is no generic way of clearing
a form (AFAIK).
- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)
"Sven Jacobs" <sven.jacobs@.web.de> wrote in message
news:178f7ojd7o9bi.719p7zwjzasv$.dlg@.40tude.net...
<form>
The
> So what you saying is that the state persistance of a form is a feature of
> HTTP / the browser? How to clear the form then, via JavaScript?
> Thanks!
> --
> Sincerely
> Sven Jacobs

Persistent ViewState

Hello everybody!

Imagine a form with several TextBox WebControls and two buttons "New" which
should clear the form and "Save". On reloading or leaving the page which
holds the form the TextBoxes should be cleared so I've disabled the
ViewStates of these TextBoxes by setting the EnableViewState property to
false.

The method which is bound to the OnClick event of the "New" button is
empty. When clicked a PostBack occurs which, theoretically, should be
sufficient to clear the TextBoxes because their state shouldn't be saved.
Unfortunately after the PostBack the data is still there! I've had a look
into the HTML source and found out that the value property of the TextBoxes
is set, so there's still a ViewState?! Even a ViewState.Clear() and/or
ClearChildViewState() within OnClick() doesn't work!

Disabling the ViewState for the whole page is no solution because the page
also contains a DataGrid and other controls which depend on the ViewState.

Please help!

--
Sincerely
Sven JacobsViewState is a different state persistance mechanism than the normal <form>
post data. ViewState is for data that is not part of the normal POST. The
text in a Label is saved in ViewState because a <span> doesn't post when
the form is submitted. The text in a TExtBox will be submitted, and thus
disabling viewstate has no effect on that.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> Hello everybody!
> Imagine a form with several TextBox WebControls and two buttons "New"
> which should clear the form and "Save". On reloading or leaving the
> page which holds the form the TextBoxes should be cleared so I've
> disabled the ViewStates of these TextBoxes by setting the
> EnableViewState property to false.
> The method which is bound to the OnClick event of the "New" button is
> empty. When clicked a PostBack occurs which, theoretically, should be
> sufficient to clear the TextBoxes because their state shouldn't be
> saved. Unfortunately after the PostBack the data is still there! I've
> had a look into the HTML source and found out that the value property
> of the TextBoxes is set, so there's still a ViewState?! Even a
> ViewState.Clear() and/or ClearChildViewState() within OnClick()
> doesn't work!
> Disabling the ViewState for the whole page is no solution because the
> page also contains a DataGrid and other controls which depend on the
> ViewState.
> Please help!
> ViewState is a different state persistance mechanism than the normal <form>
> post data. ViewState is for data that is not part of the normal POST. The
> text in a Label is saved in ViewState because a <span> doesn't post when
> the form is submitted. The text in a TExtBox will be submitted, and thus
> disabling viewstate has no effect on that.

So what you saying is that the state persistance of a form is a feature of
HTTP / the browser? How to clear the form then, via JavaScript?

Thanks!

--
Sincerely
Sven Jacobs
> So what you saying is that the state persistance of a form is a feature of
> HTTP / the browser? How to clear the form then, via JavaScript?

Forget that! After reading this article
http://aspalliance.com/articleViewer.aspx?aId=135 I think I now what the
difference between ViewState and PostBack data is.

So what I have to do is not to import the PostBack data on a special
condition (=New button clicked).

--
Sincerely
Sven Jacobs
No, the form persistance is a feature of the ASP.NET runtime, in that it
matches the control id in the POST data and fills the associated value from
that. See
http://msdn.microsoft.com/library/d...l/viewstate.asp

To clear the form, loop through the controls on the form, and check if the
control is a textbox, or certain type of control, then set the value to an
empty string, or index to -1 if a droplist etc. It really depends on what
type of control you are working with as there is no generic way of clearing
a form (AFAIK).

--

- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)

"Sven Jacobs" <sven.jacobs@.web.de> wrote in message
news:178f7ojd7o9bi.719p7zwjzasv$.dlg@.40tude.net...
> > ViewState is a different state persistance mechanism than the normal
<form>
> > post data. ViewState is for data that is not part of the normal POST.
The
> > text in a Label is saved in ViewState because a <span> doesn't post when
> > the form is submitted. The text in a TExtBox will be submitted, and thus
> > disabling viewstate has no effect on that.
> So what you saying is that the state persistance of a form is a feature of
> HTTP / the browser? How to clear the form then, via JavaScript?
> Thanks!
> --
> Sincerely
> Sven Jacobs