How to prevent the automatic client side validations execution in a ModalPopupExtender? - asp.net

I'm using a ModalPopupExtender to show a modal popup window with a bunch of input controls and a couple of validators with EnableClientScript set to true.
The issue I'm facing is, that the client-side validations get executed right after the modal popup is shown (via client-side code, not from server).
Is there a way to prevent this?

I'm currently facing the exact same problem than you.
For the moment, I've did some JavaScript to handle this situation by filling the current input with a "Default" text value. I also modify the style color when the Default value is in the input to gray color instead of black.
Then when the user click in the input, another JavaScript function is called to clear it and change the color back to Black!
So my Javascript validation are based on my input color style. I don't very like the way I'm doing this because the validator should work...
I found some informations about that there :
http://forums.asp.net/t/1066821.aspx
http://forums.asp.net/t/1057570.aspx
But actually when I'm inserting their tagMapping in my web.config, all my control in my Master page or .apsx page cannot be found in my .apsx.vb page...
P.S. If you want me to give you my current Javascript (working perfectly) just tell me :)

Related

Using jQuery Validator on dialog displayed with BlockUI

I'm still learning jQuery, and I've come up against something I'm not sure how to proceed with.
I have a form, within it is a div which is hidden (using "display: none") at load time. This div is later displayed via the BlockUI plugin as a modal dialog for the editing of certain input elements. I'm trying to get the validation plugin to check that the fields I have denoted as required are actually filled in by the end user.
I have used the validation plugin elsewhere in my app without any problems, but this is the first time I'm using it to validate inputs that are hidden at load time. The validations aren't being executed (i.e. empty text inputs that are marked as required aren't flagged as such, and .valid() returns true).
I stepped through the validation logic with Firebug and discovered that none of the input elements within the dialog div are present within $(this.currentForm). If I keep the dialog div visible and remove the $.blockUI call, then the validation works as expected.
So I think I know what the problem is now -- my inputs aren't in the DOM, because they were originally not visible, so the validation plugin doesn't know they exist. I'm not sure how to fix this. Can anyone offer a suggestion? Thanks!
EDIT: The call to $.blockUI() is removing the dialog div from the DOM. Looks like I'll have to find another way to display the dialog.
EDIT: the code is proprietary so I can't post it.
Validation plug-in link
BlockUI plug-in link

Application wide Modalpopupextender

I'm trying to build a modalpopupextender, along with a panel and content, and need to make it application-wide. I am thinking about creating it on the Masterpage, so it's accessible on all pages, but I need the content inside the panel (anything that I may need to add there) to be visible and editable from outsite the masterpage.
For now, I'm working on this, but haven't figured out how to make it accessible to other pages and classes, and so would like to have some help on it.
Basically, what I want is to work more on the idea in a near future in order to make something consistent to be used on any web application, and to be fully customizable. What I'm having trouble is with "basics", like making it accessible to the application, allow customization of some controls inside the panel from both server and client sides, and will improve everything from there.
I have tried creating a user control for it, but didn't seem to work. I'm not an expert on asp.net (few years of experience), and even less on ajax, so any help is appreciated.
Please let me know if anybody have any questions.
EDIT:
I have now succeeded somehow creating the moodal within a user control and it's almost done.
At this moment, there are 2 issues I couldn't fix:
The damn flickering that happens on Firefox 3.5 (Corporate version, can't touch this). Ocasionally during page load (Somewhere near Page_Init or Page_PreInit events, not sure), the modals I have blink quickly on the screen, only when a postback happens. I have already done some workaround, like setting style display:none, but the issue remains. Need some help on the matter.
I need to have a modal that have 2 behaviors, like windows popups. One is information, likee only showing the message with some buttons, and the other is question. For questions, I'll need to use the ConfirmButtonExtender, and so would need to tell this confirm extender and the modal that an external button (Means a button that isn't within the user control, and by that means it's outside the same UpdatePanel as the confirm extender and modal extender) will be their TargetControlID. For now, I couldn't solve this, so I thought about creating a button inside the UC and UpdatePanel that will always be the TargetControlID. When the popup is informational, it will work as a dummy hidden button (information messages are called on server-side through methods), and when it's a question, it will receive the response. The method to be executed by the button will be set through a delegate, and therefore any method may be run when it's clicked and the Yes button on the modal is pressed (It's not ready yet, and I'm not sure it will work, or even if it's a good idea).
Any thoughts on this second option is appreciated.
It's easy for elements on the masterpage to be visible and editable from outsite the masterpage.
In this example the masterpage has a label that you want to read/write from other pages
<asp:Label ID="lblSubTitle" runat="server" Text="sub title"></asp:Label>
In the codefile for the masterpage, create a property for the subtitle:
public partial class MainMasterPage : System.Web.UI.MasterPage
{
public string SubTitle
{
get
{
return lblSubTitle.Text;
}
set
{
lblSubTitle.Text = value;
}
}
}
Then any page that uses this masterpage as its MasterPageFile can find the subtitle property and read or write it.
// get a reference to the masterpage
MainMasterPage master = (MainMasterPage)Master;
//set it to the value you want.
master.SubTitle = "Custom sub title";
I have solved the issue and created a user control containing the modalpopup for showing customized messages.
Many aspects are public, so it allows high customization, and the modal and it's customized buttons work like a charm. I still have a problem regarding the flickering, but it's for another question.

How do I access Page controls from within my custom server control?

I am building a modal box as a custom server control and I want to have a property on the modal box TargetControlID that specifies the element that will show the modal when clicked. I've set the property up in the modal box and in the code behind I use the following code block (which I've tried in several different places
If (_targetControlId <> "") Then
Dim targetControl As WebControl = Me.Page.FindControl(_targetControlId)
targetControl.Attributes.Add("onclick", "test1();")
targetControl.Attributes.Add("onclick", "test2();")
End If
What happens is that targetControl always winds up to be NULL, and causes the page to crash when I tried to add attributes to it. I've double checked the spelling of the targetControlId and I am specifying a control that is runat="server". What is the proper way for a server control to access other controls on its containing page?
Thanks,
Mike
First of all, I should point out that the behavior you're looking for already exists in the ModalPopupExtender that comes with the free, open-source AjaxControlToolkit. I'd recommend you just use that. If you're still sure you want to write your own, then I'd recommend at least taking a look at their code to see how they go about it. ExtenderControlBase.FindControlHelper is a good place to start.

loading value to asp.net control using javascript

iam into problem of reading the value of the control which i alterd using javascript
the sequence goes like this
i got the text box control by using its id
cleared the value of the text box
make the control disabled.
when i tried to retrive the value of the textbox in aspx.cs
iam still getting the old value of the text box which i actualy cleared in the javascript
kindly suggest me to over come this issue
Thanks
Disabled input controls don't get their values posted back so ASP.Net doesn't know you changed the value. You need to enable the control.
With ASP.NET Web Forms, IDs for elements get assigned automatically by the Page on the server side. It is tricky, but possible, to manipulate element values using javascript. One way to avoid this would be to use ASP.NET MVC where the HTML would be rendered as is and javascript or jquery can be easily used to "play" with the HTML elements. We need more information to help you with the details of your request.

Modifying <asp:label> in form

I am developing a form using all asp:textbox and asp:label. Currently, I am using the RequiredFieldValidator to validate text boxes and display an error inline. What I am trying to do is to change the color of one of the asp:labels after validation fails for one of the textboxes fields. Would I accomplish this with javascript, or is there any commands that can do it within asp to modify labels. I would really appreciate any help and code examples.
I'd say that javascript is the way forward here if you don't want to postback to the server. If you use ASP.NET only the page will normally have to be posted back so that the server can change the properties of the label - not very user friendly. A colleague of mine has accomplished this very nicely using JQuery (a javascript libraray) but unfortunatly I don't have a copy of the code to hand. He's an SO user too so I'll pass on a link to this post for you.

Resources