473,388 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Asp.net validators

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
Jan 18 '06 #1
2 2239
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!
***************************
"Papanii Okai" wrote:
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

Jan 18 '06 #2
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

"Cowboy (Gregory A. Beamer) - MVP" <No************@comcast.netNoSpamM> wrote
in message news:AC**********************************@microsof t.com...
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!
***************************
"Papanii Okai" wrote:
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

Jan 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MonkeyBoy | last post by:
I am doing some some HTML manipulation in client-side script (IE5.x and IE6.x browsers only). Something like.. var tmpHTML = oTable.outerHTML // do something to the HTML her oTable.outerHTML =...
1
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These...
0
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These...
7
by: angus | last post by:
Dear all, I have 5 textboxes, and 2 buttons in a webform. 1-3 textboxes would be validated by 3 Required Field Validators if button 1 is click; 4-5 textboxes would be validated by 2 Required...
6
by: Mark | last post by:
We have Validators embedded in an asp table server control. The table server control is necessary and cannot be replaced. We want to apply CSS formatting to the validators, but the validators...
3
by: John Blair | last post by:
Hi, I have validators outside of a datagrid (for adding a new grid row) - however when i click "edit" column and then the "update" column of a grid row that has been edited - my other...
1
by: epigram | last post by:
I'm trying to use the ASP.NET validators to check some client-side business rules. I've got two ASP TextBox controls (call them tbxYear1 and tbxYear2) used to enter a range of years. I've got a...
1
by: Gabriel Lozano-Morán | last post by:
When using the tabstrip control combined with a multipage (several pageview) there is a problem when using validators. The problem is that validation also occurs on the validators that are not on...
2
by: Mike Surcouf | last post by:
Hi I have some regex validators on my page set to dynamic and like the way they appear after you tab out of a field and also when you try to postback the form. All OK so far When I register...
4
by: Madhur | last post by:
Hello All I am learning how to use ASP.NET Validators and would appreciate if someone could provide me with guidance. I have written very simple ASPX page below with a Dropdown list, a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.