Home All Groups Group Topic Archive Search About

Trouble with databinding

Author
11 Sep 2006 12:30 AM
Hayden Kirk
Hi,

I'm trying to add databinding to the wizard control. Basically a user is
entering their email address and I want to validate this to a sql database
when the hit next but I cannot get this to work.

Any idea how I would go about doing this?

Thanks in advance

--

- Hayden Kirk

Author
11 Sep 2006 2:35 AM
Brennan Stehling
What you need to do is handle the NextButtonClick and
PreviousButtonClick events.  In those events you can check the value
for the ActiveStepIndex which will coorespond with each of your steps.
If the right step is the current one you can run your check against the
database.  If you want to cancel the step you can set the Cancel
property on the event to true.

Here is a code snippet.

protected void Wizard1_NextButtonClick(object sender,
     System.Web.UI.WebControls.WizardNavigationEventArgs e)
{
  bool isEmailValid = FindEmail(txtEmail.Text);
  e.Cancel = ! isEmailValid();
}

You may also want to attach a custom validator to the email textbox and
then you can simply ask the validator if it is valid.  It will then
automatically display the error indicator, like a red star next to the
textbox.

Brennan Stehling
http://brennan.offwhite.net/blog/

Hayden Kirk wrote:
Show quote
> Hi,
>
> I'm trying to add databinding to the wizard control. Basically a user is
> entering their email address and I want to validate this to a sql database
> when the hit next but I cannot get this to work.
>
> Any idea how I would go about doing this?
>
> Thanks in advance
>
> --
>
> - Hayden Kirk
Author
11 Sep 2006 4:36 AM
Hayden Kirk
Thanks for responding Brennan.

This is working perfectly. I was wondering though, what is the best way to
go about getting the data from the mssql database. I only need to check to
see if their email address already exists or not, possibly delete it if they
wish to unsubscribe. Can I use the sqldatasource control for this? Or is is
better to code this by hand?

I was wondering if someone could give me a quick example of doing it by
hand.

Thanks,

Show quote
"Brennan Stehling" <offwh***@gmail.com> wrote in message
news:1157942127.738960.146550@e3g2000cwe.googlegroups.com...
> What you need to do is handle the NextButtonClick and
> PreviousButtonClick events.  In those events you can check the value
> for the ActiveStepIndex which will coorespond with each of your steps.
> If the right step is the current one you can run your check against the
> database.  If you want to cancel the step you can set the Cancel
> property on the event to true.
>
> Here is a code snippet.
>
> protected void Wizard1_NextButtonClick(object sender,
>     System.Web.UI.WebControls.WizardNavigationEventArgs e)
> {
>  bool isEmailValid = FindEmail(txtEmail.Text);
>  e.Cancel = ! isEmailValid();
> }
>
> You may also want to attach a custom validator to the email textbox and
> then you can simply ask the validator if it is valid.  It will then
> automatically display the error indicator, like a red star next to the
> textbox.
>
> Brennan Stehling
> http://brennan.offwhite.net/blog/
>
> Hayden Kirk wrote:
>> Hi,
>>
>> I'm trying to add databinding to the wizard control. Basically a user is
>> entering their email address and I want to validate this to a sql
>> database
>> when the hit next but I cannot get this to work.
>>
>> Any idea how I would go about doing this?
>>
>> Thanks in advance
>>
>> --
>>
>> - Hayden Kirk
>
Author
11 Sep 2006 12:15 PM
Brennan Stehling
Here is a snippet for a basic query with ADO.NET.

using System;
using System.Data;
using System.Data.SqlClient;

class Sample
{
  public static void Main()
  {
    SqlConnection nwindConn = new SqlConnection("Data
Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");

    SqlCommand catCMD = nwindConn.CreateCommand();
    catCMD.CommandText = "SELECT CategoryID, CategoryName FROM
Categories";

    nwindConn.Open();

    SqlDataReader myReader = catCMD.ExecuteReader();

    while (myReader.Read())
    {
      Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0),
myReader.GetString(1));
    }

    myReader.Close();
    nwindConn.Close();
  }
}



Hayden Kirk wrote:
Show quote
> Thanks for responding Brennan.
>
> This is working perfectly. I was wondering though, what is the best way to
> go about getting the data from the mssql database. I only need to check to
> see if their email address already exists or not, possibly delete it if they
> wish to unsubscribe. Can I use the sqldatasource control for this? Or is is
> better to code this by hand?
>
> I was wondering if someone could give me a quick example of doing it by
> hand.
>
> Thanks,
>
> "Brennan Stehling" <offwh***@gmail.com> wrote in message
> news:1157942127.738960.146550@e3g2000cwe.googlegroups.com...
> > What you need to do is handle the NextButtonClick and
> > PreviousButtonClick events.  In those events you can check the value
> > for the ActiveStepIndex which will coorespond with each of your steps.
> > If the right step is the current one you can run your check against the
> > database.  If you want to cancel the step you can set the Cancel
> > property on the event to true.
> >
> > Here is a code snippet.
> >
> > protected void Wizard1_NextButtonClick(object sender,
> >     System.Web.UI.WebControls.WizardNavigationEventArgs e)
> > {
> >  bool isEmailValid = FindEmail(txtEmail.Text);
> >  e.Cancel = ! isEmailValid();
> > }
> >
> > You may also want to attach a custom validator to the email textbox and
> > then you can simply ask the validator if it is valid.  It will then
> > automatically display the error indicator, like a red star next to the
> > textbox.
> >
> > Brennan Stehling
> > http://brennan.offwhite.net/blog/
> >
> > Hayden Kirk wrote:
> >> Hi,
> >>
> >> I'm trying to add databinding to the wizard control. Basically a user is
> >> entering their email address and I want to validate this to a sql
> >> database
> >> when the hit next but I cannot get this to work.
> >>
> >> Any idea how I would go about doing this?
> >>
> >> Thanks in advance
> >>
> >> --
> >>
> >> - Hayden Kirk
> >

AddThis Social Bookmark Button