Asp.net validators

P

Papanii Okai

I have a discussion forum page where, a user can add a new topic thread to
the list of threads. Now to ensure that a user supplies a title and content
to this form, I have two client side RequiredFiledvalidators "titleCheck"
and "messageCheck". Now I also have a cancel button on the page that simply
discards everything and closes the addNewThread window. But for some reason
it doesn't work. Whenever I click the cancel button the client side
validators fire.

The cancel button is a <asp:ImageButton>. Below is the code in the .aspx
file

/// code in .aspx file..///
<asp:ImageButton ID="ImageButton2" runat="server"
ImageUrl="~/images/CancelButton.gif" CommandName="cancel"
OnCommand="buttonExecute"
onmouseover="this.src='../images/CancelOverButton.gif';"
onmouseout="this.src='../images/CancelButton.gif';"/>

Below is the c# function that handles the click events..
///code///
protected void buttonExecute(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "add":
try
{
forum newThread = new forum(Label1.Text,
TitleTextBox.Text);
newThread.insertThreadTopic();
Response.Write("<script>window.close();</script>");
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine("Insert new thread
Error");
System.Diagnostics.Debug.WriteLine(err.ToString());
}
break;
case "cancel":
Response.Write("<script>window.close();</script>");
break;
default:
ErrorLabel.Visible = true;
break;
}
}
Suggestion will be appreciated..

--Papanii
 
G

Guest

Assume this is ASP.NET 1.1? In 2.0, you can create command groups that allow
you to ignore validators with certain buttons.

As a simple solution (perhaps a bit kludgy), the cancel button can be an
HTML <INPUT type="submit"> type button, with no server side. You link it to
window.close() and avoid validation altogether. That would be one simple
solution that could work in your situation, as it performs no form submit.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
P

Papanii Okai

Thanx Gregory,
After you stated that i could create command groups i
did some more research and found out that the <asp:imagebutton> has the
CausesValidation property that i can set. Thanx...

p.s. i am developing using ASP.net 2.0 by the way..

--Papanii
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,743
Latest member
WoodrowMea

Latest Threads

Top