Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Monday, March 26, 2012

Please Guide me

Hi,

I have just started learning ASP.NET. My background is in Cold Fusion, Perl, C++ and some JAVA.
I got this book on asp.net by microsoft. "ASP.NET programming with Visual Basic.NET STEP by STEP". The book is ok. I am trying to find some code samples which are good for beginners (i mean not very complex). Where can i find such samples which i can download and understand the actual usage of asp.net.

Please help me. I am lost. I have read half of the book, and still not very clear on some of the concepts. Is it easy to learn on my own or should taking some kind of training is a good idea.

Thanks.Check out:
ASPNet101.com
That should help a little to get you started, at least

also - remember that the basic concept of ASP.Net is that it is Event Driven and Object Oriented - - it brings actual programming concepts (like Visual Basic, etc) to web programming.

Every Web form tag is considered an object - - each object has properties - - (and more)
To 'Do' something with any of these objects, it requires an event, like, a button would have a Click Event (among others) - - there is no submission of a form, per se, any more - - you can program a button to do anything you'd like.

First thing I'd narrow in on, other than the basic concept of ASP.Net, is the Web Controls (Server Controls) that ASP.Net has built in (button, textbox, etc) - - - much of the real power comes from there - -
Next, I'd check out ADO.Net - - which is what ASP.Net uses for 'talking' to Databases (just about any flavor db that you need).....

Saturday, March 24, 2012

PLease Help BAsic questions

I know The questions that I am asking are stupid.
I am new to asp.net and started learning only 4 days back.
Please help me

1. Where are page_init,page_load etc events executed?(at server or at cleint
)

2. For serverSIde Control (say Button or textbox control) how to call client side java script functions?

3. If we use Serverside validators where are they going to be executed?
When a ASPX page is requested,only HTML content is sent from server.This HTML do not have anything about validating info.So does that mean all serverside validators are going to be validated at server after the postback?
Please explian this

4. ADO.NET works with disconnected data.
So what happends or how ADO.net deals when some other application modifies the table in the database that is there as datatable in disconnected dataset.

Thanks in advance1. Everything inside <script runat="server"> will be in server. Since Page_load will be written inside <script runat="server"> then it will be executed in server.

2. You can use attribute add if you are using <asp:Button> tag
Example,

BntDelete.Attributes.Add("onclick","return confirm('Are you sure you want to delete?');")

or if u use html control then

<a id="DeleteBtn" href="http://links.10026.com/?link=#" onclick="return confirm('Are you sure you want to delete?')" onserverclick="DeleteBtn_Click" runat="server">Delete</a
3.Validation controls perform both on client side and server side. You can disable clientside by using EnableClientScript property

That's all I can anwser u
1. page_init etc. are all executed on the server. Everything is done on the server other than javascript functions you have put in the page.

2. not sure on this one, I know you can just write the javascript into the page and I think you use the attribute field of the control to associate it with the functions

3. All validators are executed on the server, I think its somewhere after the Page_Init but before the Page_Load method. You can also call Page.Validate to run all the validators and the results of these are checked with Page.IsValid (for all validators) or ValidatorName.IsValid (for specific validator). Also if the user browser is IE javascript code is also written to the page so the validators are also run at the client side. This can be turned off by setting the validators EnableClientScripting attribute to false.

4. I guess it just deals with it :-) (don't know really, never had a problem with it)
for #4:

that would be a concurrency issue, probably the best thing to do is check the contents of your disconnected table against the database and notify user if it has been changed so they have the option of overwriting the database or canceling their changes.
Hi

Thank you very much for your reply

For Q3 ,you said we have to use bdelete.Attributes.add.....
This code is going to be executed only at the server.
So its aggain going to server and comes back and executes the client script.
So is there any way that executes the client script without going to server.

thanks in advance
I guess u mean q2.

for BntDelete.Attributes.Add("onclick","return confirm('Are you sure you want to delete?');")

It actually create a client script on the <input> tag. So when user click on the button...it is actually on client side. You may change the second argument to call a javascript function name.

Hope u understand.

Friday, March 16, 2012

please help me understand! ASP.Net - VB.NET

ok, so i took this sample form a site that offered to take the source code for the perpose of learning so i did. except that it is not working on my machine but its running where i got it from (the site).
could you please assist me knowing where the code went wrong?
the code is listed below:
<%@dotnet.itags.org. Page Language="VB" ClientTarget="downlevel" %>
<%@dotnet.itags.org. Import Namespace="System.Web.Mail" %>

<script language="VB" runat="server">
Sub btnSendMail_OnClick(Source As Object, E As EventArgs)
Dim myMessage As New MailMessage
Dim myMail As SmtpMail
Dim strEmail As String

If Page.IsValid() Then
strEmail = txtEmail.Text

myMessage.From = "webmaster@dotnet.itags.org." & Request.ServerVariables("SERVER_NAME")
myMessage.To = strEmail
myMessage.Subject = "E-mail Sample from ASP 101!"
myMessage.Body = "This message was sent from sample code by " & _
"http://www.asp101.com. It is used to show people how " & _
"to send e-mail from an ASP+ page. This mail was sent " & _
"from " & Request.ServerVariables("SERVER_NAME") & ". " & _
vbCrLf & vbCrLf & _
"This email was sent to " & strEmail & "."

' Doesn't have to be local... just enter your
' SMTP server's name or ip address!
myMail.SmtpServer = "localhost"
myMail.Send(myMessage)

frmEmail.Visible = False
lblUserMessage.Text = "Your message has been sent to " & strEmail & "."
End If
End Sub
</script>

<html>
<head>
<title>ASP+ Email Sample</title>
</head>
<body>

<asp:Label id="lblUserMessage" text="Enter your e-mail address:" runat="server" />
<form method="post" id="frmEmail" runat="server">
<asp:TextBox id="txtEmail" size="30" runat="server" />
<asp:RequiredFieldValidator runat="server"
id="validEmailRequired" ControlToValidate="txtEmail"
errormessage="Please enter an email address."
display="Dynamic" />
<asp:RegularExpressionValidator runat="server"
id="validEmailRegExp" ControlToValidate="txtEmail"
ValidationExpression="^[\w-]+@dotnet.itags.org.[\w-]+\.(com|net|org|edu|mil)$"
errormessage="Please enter a valid email address."
Display="Dynamic" />

<asp:Button id="btnSendMail" text="Send Mail!" OnClick="btnSendMail_OnClick" runat="server" />
</form>

</body>
</html>

Thanks,
Rami Wahdan.

Hello,

I'm beginner also, but what I would try is:

Change line:
myMessage.From = "webmaster@." & Request.ServerVariables("SERVER_NAME")

into:
myMessage.From = "your@.email.com"

and delete these lines:
' Doesn't have to be local... just enter your
' SMTP server's name or ip address!
myMail.SmtpServer = "localhost"


Rami,

it would also help if you would paste the exact error you are getting ... that will help in identifying your problem ...

cheers,

erik


ok so the error is:

Server Error in '/ASP.NET/email' Application.

The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Runtime.InteropServices.COMException: The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com
Source Error:
The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:
1. Add a "Debug=true" directive at the top of the file that generated the error. Example:
<%@. Page Language="C#" Debug="true" %>
or:
2) Add the following section to the configuration file of your application:
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
</configuration>
Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.
Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:
[COMException (0x8004020f): The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com][TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0 System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) +1966108 System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +56[HttpException (0x80004005): The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com] System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +105 System.Web.Mail.CdoSysHelper.Send(MailMessage message) +3632 System.Web.Mail.SmtpMail.Send(MailMessage message) +102 System.Web.Mail.SmtpMail.Send(MailMessage message) +0 ASP.email_aspx.btnSendMail_OnClick(Object Source, EventArgs E) +325 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +232 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +5 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5157


Version Information: Microsoft .NET Framework Version:2.0.40607.16; ASP.NET Version:2.0.40607.16

hmm, the error seems rather clear, what exactly did you do to solve it?
>The server rejected one or more recipient addresses. The server response was: 550 5.7.1 Unable to relay for a@.a.com
this means that the address you are sending to (a@.a.com) does not exist ...
to prevent this error to cause this page to display, you could add a Try ... Catch ... End Try statement around myMail.send(myMessage), like this:
Try
myMail.Send(myMessage)
Catch ex as Exception
End Try
Mind you, this only prevents the application to stop on the error, you should add code to handle the error properly
HTH
cheers,
erik