I have the following in my .aspx file:
<asp:CustomValidator
ID="JobIDCustomFieldValidator"
runat="server"
ControlToValidate="JobID"
OnServerValidate="jobIDCustom_ServerValidate"
EnableClientScript="false"
SetFocusOnError="true"
Display="Dynamic"
ErrorMessage="! - Not Found"
CssClass="validationError">
</asp:CustomValidator>
<br />
<asp:TextBox ID="JobID" runat="server"></asp:TextBox>
<asp:Button runat="server" ID="ProcessButton" Text="Process" onclick="ProcessButton_Click" />
I have the following in my code behind file:
protected void ProcessButton_Click(object sender, EventArgs e)
{
Response.Write("I am in here");
}
protected void jobIDCustom_ServerValidate(object sender, ServerValidateEventArgs e)
{
// Impersonate a user for shared folder access.
using (UserImpersonation user = new UserImpersonation(properties.ShareUser, properties.Domain, properties.SharePassword))
{
e.IsValid = false;
// Check the user credentials.
if (user.ImpersonateValidUser())
{
e.IsValid = File.Exists(@"\\\\" + properties.RemoteServer + "\\" + properties.Share + "\\" + JobID.Text + ".dat");
}
}
}
I want the custom validator to be checked first and if it is false stop and do not run any of the code in the ProcessButton_Click() method. Is this possible? If not is there an alternative way I could set this up?
As far as I know I can't use client side validation with javascript to do the impersonating and file access.
Any help would be greatly appreciated.