Showing posts with label ASP. Show all posts
Showing posts with label ASP. Show all posts

Apr 11, 2010

11:58 PM - , No comments

Auto size text box

There is a way to auto size a asp text box or others web controls with jquery library. The steps:

1. Register onResize event:
window.onresize = windowOnResize;

2. Implement windowOnResize function:
Suppose that you want your txtLogView displays 800px of width and 500px of height, add this snip code:

var myWidth = 800px;
var myHeight = 500px;
var myStyle = "width:" + myWidth + ";height:" + myHeight ;
$('#<%=txtLogView.ClientID%>').attr('style', myStyle);

Apr 8, 2010

3:01 AM - No comments

Some useful validate functions

Here're some useful functions when you're working with validation.

//Enable or disable page's validations at run time
1. Page_ValidationActive = boolean;

//Force to validate controls or group of controls.
2.Page_ClientValidate();

//Enable or disable a special validator:
3. ValidatorEnable(client_id, boolean);

//Validate a control:
4. ValidatorValidate(val);

5. ???
ValidatorUpdateIsValid();

6.???
ValidatorUpdateDisplay(val)
7.More ?
Here

Mar 30, 2010

12:38 AM - , No comments

Scroll to the bottom of textbox as default

You want your textbox auto scroll to the bottom instead of the top as default page load?

Okie, do it like this:

Winform:

txtMyText.SelStart = Len(txtMyTest.Text)

:D

Ofcouse I don't mention about Winform app, you can find variety of solutions in Google. I want to talk about asp.net. Okie, not take your time:
Place this snip code on your LoadPage (aspx, javascript, does not .cs)

var txtMyText = window.document.getElementById("<%=txtMyText.ClientID %>");
txtMyText.doScroll();
txtMyText.scrollTop = txtMyText.scrollHeight;

Hope this help :)

Mar 9, 2010

11:47 PM - No comments

Apply css for CallOut Validator

AjaxToolkit:ValidatorCalloutExtender provides CssClass property to help you make your own style to display popup.
For example:


<ajaxToolkit:ValidatorCalloutExtender runat="Server" ID="vceCUSIP" TargetControlID="reqCUSIP"
HighlightCssClass="validatorCalloutHighlight" CssClass="CustomValidatorCUSIP" PopupPosition="Left" />

But you not only re-defined css class CustomValidatorCUSIP but also re-defined all items in this style sheet. Another word, you must overwrite default style provides by ajaxToolkit:


<style id = "CUSIPStyle" type="text/css">

.CustomValidatorCUSIP
{
position: relative;
margin-left: 0px;
margin-top: 0px;
display: inherit;
}
.CustomValidatorCUSIP div
{
border: solid 1px Black;
position: relative; /*boder arrow
border: solid 1px red; */
background-color: #fcfdd8;
}
.CustomValidatorCUSIP td
{
border: solid 1px Black;
background-color: #fcfdd8;
}
.CustomValidatorCUSIP .ajax__validatorcallout_popup_table
{
display: none;
border: none;
background-color: transparent;
padding: 0px; /*
border: solid 1px red; */
}
.CustomValidatorCUSIP .ajax__validatorcallout_popup_table_row
{
vertical-align: top;
height: 100%;
background-color: transparent;
padding: 0px;
}
.CustomValidatorCUSIP .ajax__validatorcallout_callout_cell
{
width: 20px;
height: 100%;
text-align: right;
vertical-align: top;
border: none;
background-color: transparent;
padding: 0px;
}
.CustomValidatorCUSIP .ajax__validatorcallout_callout_table
{
height: 100%;
border: none;
background-color: transparent;
padding: 0px; /*chứa arrow
border: solid 1px green;
*/
}
.CustomValidatorCUSIP .ajax__validatorcallout_callout_table_row
{
background-color: transparent;
padding: 0px;
}
.CustomValidatorCUSIP .ajax__validatorcallout_callout_arrow_cell
{
padding: 8px 0px 0px 0px;
text-align: right;
vertical-align: top;
font-size: 1px;
border: none;
background-color: transparent;
}
.CustomValidatorCUSIP .ajax__validatorcallout_callout_arrow_cell .ajax__validatorcallout_innerdiv
{
font-size: 1px;
position: relative;
left: 1px;
border-bottom: none;
border-right: none;
border-left: none;
width: 15px;
background-color: transparent;
padding: 0px;
}
.CustomValidatorCUSIP .ajax__validatorcallout_callout_arrow_cell .ajax__validatorcallout_innerdiv div
{
height: 1px;
overflow: hidden;
border-top: none;
border-bottom: none;
border-right: none;
padding: 0px;
margin-left: auto; /*
border: solid 2px #3a6ea5;
*/
}
.CustomValidatorCUSIP .ajax__validatorcallout_error_message_cell
{
font-family: Verdana;
font-size: 10px;
padding: 5px;
border-right: none;
border-left: none;
width: 100%;
}
.CustomValidatorCUSIP .ajax__validatorcallout_icon_cell
{
width: 20px;
padding: 5px;
border-right: none;
}
.CustomValidatorCUSIP .ajax__validatorcallout_close_button_cell
{
vertical-align: top;
padding: 0px;
text-align: right;
border-left: none;
}
.CustomValidatorCUSIP .ajax__validatorcallout_close_button_cell .ajax__validatorcallout_innerdiv
{
border: none;
text-align: center;
width: 10px;
padding: 2px;
cursor: pointer;
}
</style>

Feb 7, 2010

11:45 PM - ,, 1 comment

Disable CallOut Validator

AjaxToolkit ValidatorCalloutExtender control provides you a new (of course, a nice) way to display your validate message. Although still have some inconveniences but it's worth to try :))

One of inconveniences is when you disable your target validator control by JavaScript (4 example, call ValidatorEnable(targetValidateControl, false)) the callout validator popup still shows every time you focus to the control.

Here's the solution to fix this issuer :

1.Set CSS class for ValidatorCalloutExtender:

HTML Code:

<style id = "style1" type="text/css">
.CustomValidator
{
position: relative;
margin-left: -80px;
margin-top: 8px;
display: inherit;
}
</style>
<ajax:ValidatorCalloutExtender ID="ProductIncrementVE" runat="server"
TargetControlID="ProductIncrementValidator"
HighlightCssClass="validator"
WarningIconImageUrl="~/img/blank.gif"
CssClass="CustomValidator">


</ajax:ValidatorCalloutExtender>

2 . Use JavaScript to alter this CSS class when needed. Set display = none:

Mã:

function alterDisplay(type) {
var styleSheet, cssRule;
if (document.styleSheets) {
styleSheet = document.styleSheets[index1];
if (styleSheet) {
if (styleSheet.cssRules)
cssRule = styleSheet.cssRules[index2]; // Firefox
else if (styleSheet.rules)
cssRule = styleSheet.rules[index2]; // IE
if (cssRule) {
cssRule.style.display = type;
}
}
}
}

Note: the index1 and index2 may be difference from pages, it's up to your declaration. You can use IE debugger to find our the correctly index.
Hope they fix this problem in next release.

Feb 3, 2010

9:58 PM - , No comments

Validate with OnClientClick

Using an OnClientClick function in submit button like:

<asp:Button ID="btnFinish" runat="server" SkinID="ButtonWidth50" Text="Finish" OnClientClick="return CheckForm()"/>

maybe lets your validate controls do not work correctly.

When the CheckForm() returns a true value, your page goes thought to sever and does not execute validate functions.

Solution:
call Page_ClientValidate() function to force controls do there's validate tasks before goes to another processing.

function CheckForm() {
var result = true;
result = Page_ClientValidate();
if (result){
// Do your task here
}
return result;
}