user: psw:
| lost password
ASP.NET 3.5 For Dummies :: Forums
Home » Technical questions » Page 58 about insertion at <script> and </script> Messages in this topic - RSS
12/3/2009 10:11:30 PM
paddyinuae
Posts 2
Hi Ken,

Thanks for the amazingly prompt reply - you should do this as a business :-)!

All fixed - it works like a charm.
I probably would never have figured out the syntax to that import statement.

Thanks very much for the help, and great book btw.
It's made all the better for the eratta (minor though it is), download chapter code, and this forum.
Well done, and thanks again.

Ian.
12/3/2009 12:05:24 PM
Ken Cox
Posts 170
paddyinuae wrote:
I've tried all sorts of techniques and I've pasted that import directive just about everywhere, but still can't get the examples to work with code behind.


Hi Ian,

Could you post the code that's not working?

In the codebehind, you use the Imports statement with a different syntax:

Imports System.Linq

Partial Class linqtest
Inherits System.Web.UI.Page
Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
Dim q = From f In System.Drawing.FontFamily.Families
For Each fnt In q
Response.Write(fnt.Name & "<br />")
Next
End Sub
End Class

Does the preceding work for you?

Ken
12/3/2009 8:54:33 AM
paddyinuae
Posts 2
Greetings.

I've looked through the FAQs, and I apologize in advance if this is a dumb question. As it's to do with LINQ and code behind files, I though here would be an opportune place to raise the question.

I notice that all examples use the "single page model" of coding. I've successfully followed the examples in the book, but would like to use the ""code behind model" of coding. I've tried all sorts of techniques and I've pasted that import directive just about everywhere, but still can't get the examples to work with code behind.

Can it be done, and if so, how difficult is it?

Thanks in anticipation.

Ian.
4/29/2009 11:27:33 AM
n_williams
Posts 1
Hello there,

I too have been having problems with page 58 item 6. I have read the other posts before posting this and I now understand why I couldn't see the script tags, I have downloaded the C# code for Chapter 4 from this site and I can't understand why the following code:

script runat="server">


protected void CustomValidator1_ServerValidate
(object source, ServerValidateEventArgs args)
{
args.IsValid = IsDate(args.Value.ToString());
}

public bool IsDate(string inValue)
{
try
{
DateTime myDT = DateTime.Parse(inValue);
return true;
}
catch (FormatException e)
{
return false;
}
return false;
}

</script>

is listed when all it says on page 59 after having inserting the procedure that handles the CustomValidator1ServerValidate event to insert the following code:

args.IsValid = IsDate (args.Value) - this is the VB code listed in the book.
It doesn't mention adding the rest of the above code in.

I am now extremeley confused!!! I was getting on great until this now I feel a bit deflated...

Can you explain this please.

Nicola
edited by n_williams on 4/29/2009
8/19/2008 5:35:14 PM
MHartman
Posts 1
For some of the forum members, who might be having the same problem as I was ...

I too struggled with making the "Not a valid date!" on the CustomValidator control work properly. However, my problem wasn't the use of the code behind model. What I found out was that I was entering an invalid date format through the "edit" function of the GridView control NOT through the "new" function of the FormView control.

When I entered "blahblah" into the Formview, it worked fine. However, in the GridView entering "blahblah" I got the server error message.

I didn't realize the validator only worked on the FormView control.
6/20/2008 11:10:01 PM
dcastor
Posts 3
Yea, I'll leave a review on Amazon and Buy.com upon completion . It has a very good rating -- currently 4.5/5 -- on Amazon. I'm sure it'll pick up . I'm sure I'll be back with more questions, seeing as I am totally new to ASP.net and still reading. Talk to ya soon. Take care.
6/20/2008 10:42:52 PM
Ken Cox
Posts 170
dcastor wrote:
Alright, that did it . Thanks for all the help Ken. It is much appreciated.


My pleasure! Anytime you're stuck, this is the place.

And if you get a chance, please post a review somewhere? The book has been a critical success (very gratifying) but not selling that well (less gratifying).

Thanks,

Ken
6/20/2008 2:16:03 PM
dcastor
Posts 3
Alright, that did it . Thanks for all the help Ken. It is much appreciated.
6/20/2008 1:48:15 PM
Ken Cox
Posts 170
dcastor wrote:
Hi Ken. I am having the same issue on page 58; however, unlike the previous posters, I have no clue about what's going on.


No problem. Let's see if we can get you going again....

1. In VWD, open the page in Source View (the page that's having a problem, that is).
2. At the top of the source code, replace the existing <%@ Page... directive with this one:

<%@ Page Language="VB" %>

3. Below the <!DOCTYPE declaration line, add the following:

<script runat="server">

</script>


4. Save the page.
5. In Solution Explorer, look for the old default.aspx.vb file and delete it.

This should get you back on track to continue at the top of Page 58. (You should be able to browse to the page as well.)

Just remember that the book uses the single page model of coding. Whenever you start a new page (using File > New File > Web Form) you must be sure to uncheck the checkbox for Place Code in Separate File. It should look like this screen capture:

(http://www.kencox.ca/notinaseparatefile.gif)

The complete source code for the chapter is here:

http://www.dummies.com/WileyCDA/DummiesTitle/ASP-NET-3-5-For-Dummies.productCd-0470195924,page-1.html

Finally, here's how your source code should look when you're done:

<%@ Page Language="VB" %>


<script runat="server">

Protected Sub CustomValidator1_ServerValidate _
(ByVal source As Object, ByVal args As _
System.Web.UI.WebControls.ServerValidateEventArgs)

args.IsValid = IsDate(args.Value)
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Julie's DVDs</title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." AllowSorting="True"
CellPadding="4" ForeColor="#333333" GridLines="None">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="DateAdded" HeaderText="Date Added"
SortExpression="DateAdded" ApplyFormatInEditMode="True"
DataFormatString="{0:MMM d, yyy}" HtmlEncode="False" />
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="SqlDataSource1">
<InsertItemTemplate>
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
Date Added:
<asp:TextBox ID="DateAddedTextBox" runat="server"
Text='<%# Bind("DateAdded") %>' />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="DateAddedTextBox" Display="Dynamic"
ErrorMessage="Not a valid date!"
OnServerValidate="CustomValidator1_ServerValidate" SetFocusOnError="True"
ValidateEmptyText="True"></asp:CustomValidator>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
 <asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
</ContentTemplate>
</asp:UpdatePanel>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:JulieDVDConnectionString1 %>"
DeleteCommand="DELETE FROM [Movies] WHERE [ID] = @ID"
InsertCommand="INSERT INTO [Movies] ([Title], [Description], [DateAdded]) VALUES (@Title, @Description, @DateAdded)"
ProviderName="<%$ ConnectionStrings:JulieDVDConnectionString1.ProviderName %>"
SelectCommand="SELECT [ID], [Title], [Description], [DateAdded] FROM [Movies]"
UpdateCommand="UPDATE [Movies] SET [Title] = @Title, [Description] = @Description, [DateAdded] = @DateAdded WHERE [ID] = @ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="DateAdded" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="DateAdded" Type="DateTime" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>
6/20/2008 11:36:09 AM
dcastor
Posts 3
Hi Ken. I am having the same issue on page 58; however, unlike the previous posters, I have no clue about what's going on. I understand the code-behind topic, but I don't understand how to solve it. I don't even know what 'a new page' is in your previous reply. Forgive me, I've never worked with ASP before . Can you walk me through step-by-step how to fix this so that I can get on to object #8 on 59? #6 and #7 have had me stumped for like 2 hours now. Thanks.
5/23/2008 4:44:24 AM
idfor
Posts 2
Yes it did appear, thanks for your help!
5/22/2008 11:17:21 AM
Ken Cox
Posts 170
Hi!

Regarding the <script> tags, when you add a new Web Form, did you uncheck the box for "Place code in separate file"? As you saw in a previous message, if you use the code-behind model (2 separate files) you don't get the script tags.

Try adding a new page while unchecking the box, and see if the tags appear?

Let us know?

Ken
5/22/2008 3:23:35 AM
idfor
Posts 2
Hi Ken,

Your book is awesome, i am always tempted to try out something new and up my pace. Sadly i work in a job not related to web programming so most of the learning is during my free time and over the weekend.

I have one question on the same page (58), somehow i am unable to view the <script runat=”server”> and </script> tags when i create the page.

Do i need to add server controls before i can view them mentioned in the step below?

I saw the reply and tried but the drop down is blank, any reasons for that. Here is what i did, selected the custom valdiator, clicked on the lightning bolt, servervalidate is blank.


Thanks for your help

sd
edited by idfor on 5/22/2008
4/28/2008 11:30:35 PM
Ken Cox
Posts 170
Hi and welcome to the site!

Let's see if we can get you going again....

You don't get server-side <script> tags when using code-behind. If you open the *.vb file, you see the equivalent code area.

As for locating the Object dropdown, let's try in another way to replace Step 8 on page 59:

1. In Design view, select the Custom Validator that you added to the page.
2. Open its Properties page (F4).
3. At the top of the Properties page, click the lightning bolt which represents events.
4. In the list of events, double-click on the word ServerValidate. An event handler is create and you switch to code view.

The code it creates should look like this (reformatted here):

Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As _
System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate

End Sub


You should be able to proceed with Step 9.

Let me know how you make out with this? We're here to help!!

Ken
4/25/2008 3:17:08 PM
Featheriver
Posts 2
I'm looking at item 6 on page 58. It instructs me to "Switch to Source view and put the cursor between the <script runat="Serve"> and </script> tags.

For the life of me I cannot find either of those tags on the default.aspx page. I am using the "code-behind" method and I cannot find the script on the default.aspx.vb page either.

Past that, assuming I can ever figure out my <script> </script> mystery, the next item 7 reads "In the Object drop-down list (top area of the source code frame), choose Custom validator1, as shown in Figure 4-13."

I cannot find it either. I've looked on both the default.aspx page and the default.aspx.vb page without success.

I'm at a loss. I hope someone can steer me the right way.

Maybe I need a Dummie book for Dummie books!

Anyway, thanks for any help anyone can provide.
pages: 1
|

Home » Technical questions » Page 58 about insertion at <script> and </script>