K
Kelly
I'm fairly new to ASP.NET2, but I have an ASP 3.0 background, and I've been
experimenting with the DataSource and FormView widgets. I wound up having
some questions along the way which I hope you all can address to help me
understand events with these better.
I've been reading up on inserted/inserting also deleted/deleting, but where
is it better to run call those events from via formview or datasource?
Also, I have been trying to figure out how to do you compare in the database
before posting.
I've figured that I would have to run the select() sub function while in the
inserting() sub function, but I just can't figure out how to call it so I
can compare what the user has entered before writing to the database.
Ideas?
I'm using mysql odbc connector and the code looks like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:LocalConnection %>"
ProviderName="<%$ ConnectionStrings:LocalConnection.ProviderName %>"
InsertCommand="INSERT INTO newsletter_TBL(ID, name, email, serialno, Verify)
VALUES ('', ?, ?, ?, 0)"
SelectCommand="SELECT `email` FROM `newsletter_TBL` WHERE theEmail = email">
<SelectParameters>
<asp:FormParameter FormField="emailTextBox" Name="theEmail" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" CssClass="signuptable" runat="server"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
OnPageIndexChanging="FormView1_PageIndexChanging"
OnInserting="FormView1_ItemInserting" DefaultMode="Insert" Width="288px"
Height="251px" CellPadding="10">
<InsertItemTemplate>
<span class="signuplabel">name:</span><br />
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>'
Width="250px" AutoCompleteType="FirstName"></asp:TextBox><br />
<span class="signuplabel">email:</span><br />
<asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>'
Width="250px" AutoCompleteType="Email"></asp:TextBox><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
runat="server" ControlToValidate="emailTextBox"
ErrorMessage="Invalid email, please try again"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Width="250px"></asp:RegularExpressionValidator>
<asp:TextBox ID="serialnoTextBox" runat="server" Text='<%# Bind("serialno")
%>' Visible="False" Height="0px"
OnLoad="serialnoTextBox_Load">MakeRandom()</asp:TextBox><br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="true"
CommandName="Select" Text="Sign me up"
UseSubmitBehavior="false" OnClick="InsertButton_Click" />
</InsertItemTemplate>
</asp:FormView>
.... then on the attached code page I have this
Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Try
SqlDataSource1.Insert()
Catch except As Exception
'MsgBox(except.Message)
End Try
End Sub
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting
Dim MessageLabel As String = ""
Dim itemArray(e.Values.Count - 1) As DictionaryEntry
e.Values.CopyTo(itemArray, 0)
Dim entry As DictionaryEntry
For Each entry In itemArray
MessageLabel &= entry.Key.ToString() & "= " & entry.Value & "<br/>"
Next
MsgBox(MessageLabel)
End Sub
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
SqlDataSource1.Selected
MsgBox("Select just ran + " & e.AffectedRows)
End Sub
Finally, I've been looking for information on <%%> tags because I've noticed
they've changed. You either do <%$ %> or <%# %> what are the new specialized
tag versions? Did the standard <% %> tags go away?
Thanks,
Kelly
experimenting with the DataSource and FormView widgets. I wound up having
some questions along the way which I hope you all can address to help me
understand events with these better.
I've been reading up on inserted/inserting also deleted/deleting, but where
is it better to run call those events from via formview or datasource?
Also, I have been trying to figure out how to do you compare in the database
before posting.
I've figured that I would have to run the select() sub function while in the
inserting() sub function, but I just can't figure out how to call it so I
can compare what the user has entered before writing to the database.
Ideas?
I'm using mysql odbc connector and the code looks like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:LocalConnection %>"
ProviderName="<%$ ConnectionStrings:LocalConnection.ProviderName %>"
InsertCommand="INSERT INTO newsletter_TBL(ID, name, email, serialno, Verify)
VALUES ('', ?, ?, ?, 0)"
SelectCommand="SELECT `email` FROM `newsletter_TBL` WHERE theEmail = email">
<SelectParameters>
<asp:FormParameter FormField="emailTextBox" Name="theEmail" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" CssClass="signuptable" runat="server"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
OnPageIndexChanging="FormView1_PageIndexChanging"
OnInserting="FormView1_ItemInserting" DefaultMode="Insert" Width="288px"
Height="251px" CellPadding="10">
<InsertItemTemplate>
<span class="signuplabel">name:</span><br />
<asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>'
Width="250px" AutoCompleteType="FirstName"></asp:TextBox><br />
<span class="signuplabel">email:</span><br />
<asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>'
Width="250px" AutoCompleteType="Email"></asp:TextBox><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator2"
runat="server" ControlToValidate="emailTextBox"
ErrorMessage="Invalid email, please try again"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Width="250px"></asp:RegularExpressionValidator>
<asp:TextBox ID="serialnoTextBox" runat="server" Text='<%# Bind("serialno")
%>' Visible="False" Height="0px"
OnLoad="serialnoTextBox_Load">MakeRandom()</asp:TextBox><br />
<asp:Button ID="InsertButton" runat="server" CausesValidation="true"
CommandName="Select" Text="Sign me up"
UseSubmitBehavior="false" OnClick="InsertButton_Click" />
</InsertItemTemplate>
</asp:FormView>
.... then on the attached code page I have this
Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Try
SqlDataSource1.Insert()
Catch except As Exception
'MsgBox(except.Message)
End Try
End Sub
Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting
Dim MessageLabel As String = ""
Dim itemArray(e.Values.Count - 1) As DictionaryEntry
e.Values.CopyTo(itemArray, 0)
Dim entry As DictionaryEntry
For Each entry In itemArray
MessageLabel &= entry.Key.ToString() & "= " & entry.Value & "<br/>"
Next
MsgBox(MessageLabel)
End Sub
Protected Sub SqlDataSource1_Selected(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles
SqlDataSource1.Selected
MsgBox("Select just ran + " & e.AffectedRows)
End Sub
Finally, I've been looking for information on <%%> tags because I've noticed
they've changed. You either do <%$ %> or <%# %> what are the new specialized
tag versions? Did the standard <% %> tags go away?
Thanks,
Kelly