| | |
Help with ASP code
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi, everyone out there I am new to Daniweb but have been reading the forums. I'm glad that I joined. I am in desperate need of help in coding a web page that grabs the name and email address of all the peoples from a database and then when the viewer clicks on a person a form will be displayed so the user can enter their Name, Email and write a message, then when they click submit the message will be sent to the email of the person they clicked on. I have ben working on this for a month now, but still have no results. Any help would be greatly appreciated.
Thanks.
HappyHappy
Thanks.
HappyHappy
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
What you need to do is pull all the information on the database out using something like:
Depending on the size of your database and the records it contains, you may want to add a paging function for this and limit the amount of users shown. It would be difficult to find one user if 2,000 are listed on the same page.
Then you will need to display them accordingly. You can use a DataList for the functionality of multiple columns ordered any way you wish, or you can user a repeater for ease, but you will only have 1 column unless you split it up, which you should do the datalist then.
Then you will create it like this:
Then on your mailpage.aspx, use a query to pull the information you need from the querystring and database:
It could definitely be a lot better, but it should be something to point you in the right direction. If you are set on the "onclick popup an email div/dialog and send the email", then you will need lots of javascript. Otherwise, no one will care much about the second page. To save database usage I have put the ID and username in the query string to stop a first call, and only call when the user submits the form. You can use a Scalar instead of a Reader, which would be more efficient, just test to see if the email string is long enough. Usually it's hard to have an email less than 8 characters (5 are strictly for "@", ".", and "com"). So test that it is at least 5 characters in length.
ASP.NET Syntax (Toggle Plain Text)
"SELECT DISTINCT UserID, UserName FROM Users WHERE NOT UserID IS NULL AND NOT UserName IS NULL"
Then you will need to display them accordingly. You can use a DataList for the functionality of multiple columns ordered any way you wish, or you can user a repeater for ease, but you will only have 1 column unless you split it up, which you should do the datalist then.
Then you will create it like this:
ASP.NET Syntax (Toggle Plain Text)
<asp:DataList ID="dlUsers" RepeatColumns="3" runat="server> <HeaderTemplate> <!-- if needed, use it. otherwise get rid of it --> <strong>Users</strong> </HeaderTemplate> <ItemTemplate> <!-- Use <A> if you are going to have the form on another page, otherwise use controls like LinkButton or Label. This is not easy with only ASP.NET, you will need javascript if you wish it to be same page as well. --> <a href="mailpage.aspx?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>&name=<%# DataBinder.Eval(Container.DataItem, "UserName") %>"><%# DataBinder.Eval(Container.DataItem, "UserName") %></a> </ItemTemplate> <FooterTemplate> <!-- if don't need, get rid of FooterTemplate --> </FooterTemplate>
ASP.NET Syntax (Toggle Plain Text)
<script language="vb" runat="server"> Sub SendEmail(ByVal S As Object, ByVal E As EventArgs) Dim conPubs As New OdbcConnection( "connstring" ) Dim cmdSelect As New OdbcCommand( "SELECT UserEmail FROM Users WHERE UserID=?", conPubs ) cmdSelect.Parameters.AddWithValue( "?UserID", Trim(Request.QueryString("id")).ToString ) conPubs.Open() Dim dtrReader As OdbcDataReader = cmdSelect.ExecuteReader() if dtrReader.HasRows then while dtrReader.Read() Dim strEmail As String = dtrReader("UserEmail") end while dtrReader.Close() conPubs.Close() else dtrReader.Close() conPubs.Close() response.redirect("error.aspx?error=invalid+id") end if if Not strEmail Is Nothing then 'email stuff here else response.redirect("error.aspx?error=no+email") end if End Sub </script> <HTML> <HEAD></HEAD> <BODY> Send <%= Trim(Request.QueryString("name")) %> a Message: <form name="sendemail"> <!-- form elements <asp:Button id="btnSend" OnClick="SendEmail" text="send message" runat="server" /> --> </form> </BODY> </HTML>
Last edited by SheSaidImaPregy; Jan 15th, 2008 at 6:12 pm.
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Solved Threads: 0
I have created a database and have display it onto a datalist as you said, but now I need to write code that will take me to a form when I click on the name of a person on the page. After it takes me to the form and I fill it out and press send I need the form to be sent to the email address of the person that I clicked on. The email address is in the database already with the person's information. Also the form will be on another page. Can you help me? Also can you explain in more detail this part:
It's just that I don't understand whats going on there. You're probably the only one who can help me since I can't find anything else about this. Thank you
ASP.NET Syntax (Toggle Plain Text)
<asp:DataList ID="dlUsers" RepeatColumns="3" runat="server> <HeaderTemplate> <!-- if needed, use it. otherwise get rid of it --> <strong>Users</strong> </HeaderTemplate> <ItemTemplate> <!-- Use <A> if you are going to have the form on another page, otherwise use controls like LinkButton or Label. This is not easy with only ASP.NET, you will need javascript if you wish it to be same page as well. --> <a href="mailpage.aspx?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>&name=<%# DataBinder.Eval(Container.DataItem, "UserName") %>"><%# DataBinder.Eval(Container.DataItem, "UserName") %></a> </ItemTemplate> <FooterTemplate> <!-- if don't need, get rid of FooterTemplate --> </FooterTemplate><asp:DataList ID="dlUsers" RepeatColumns="3" runat="server> <HeaderTemplate> <!-- if needed, use it. otherwise get rid of it --> <strong>Users</strong> </HeaderTemplate> <ItemTemplate> <!-- Use <A> if you are going to have the form on another page, otherwise use controls like LinkButton or Label. This is not easy with only ASP.NET, you will need javascript if you wish it to be same page as well. --> <a href="mailpage.aspx?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>&name=<%# DataBinder.Eval(Container.DataItem, "UserName") %>"><%# DataBinder.Eval(Container.DataItem, "UserName") %></a> </ItemTemplate> <FooterTemplate> <!-- if don't need, get rid of FooterTemplate --> </FooterTemplate>
Last edited by peter_budo; Feb 4th, 2008 at 6:33 pm. Reason: Please use code tags for posting of your code
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
That's exactly what I meant. Here:
All this is saying that is if you are going to have the form on the same page (which you're not), then user a server control. If you're not (which you're not!), then use an "A" link meaning <a href="..."></a> to head to the page you need to. So simple way of doing it is this:
Then on the "PageYouNeedToRedirectTo", let a user type in the information to send, a textbox you know? Then once they are ready to send it, have them click a button. The button should have an OnClick event that leads to a sub ( onClick="btnSendEmail_Click" ). Then within that sub, request the querystring and look up the information in the database. If it exists, then attempt to send the email. If it doesn't, alert the user of the problem.
If you need help, let me know.
ASP.NET Syntax (Toggle Plain Text)
<asp:DataList ID="dlUsers" RepeatColumns="3" runat="server> <HeaderTemplate> <!-- if needed, use it. otherwise get rid of it --> <strong>Users</strong> </HeaderTemplate> <ItemTemplate> <!-- Use <A> if you are going to have the form on another page, otherwise use controls like LinkButton or Label. This is not easy with only ASP.NET, you will need javascript if you wish it to be same page as well. --> <a href="mailpage.aspx?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>&name=<%# DataBinder.Eval(Container.DataItem, "UserName") %>"><%# DataBinder.Eval(Container.DataItem, "UserName") %></a> </ItemTemplate> <FooterTemplate> <!-- if don't need, get rid of FooterTemplate --> </FooterTemplate>
ASP.NET Syntax (Toggle Plain Text)
<asp:DataList ID="dlUsers" RepeatColumns="3" runat="server> <HeaderTemplate> <!-- if needed, use it. otherwise get rid of it and design your own way --> <strong>Users</strong> </HeaderTemplate> <ItemTemplate> <a href="PageYouNeedToRedirectTo.aspx?id=<%# DataBinder.Eval(Container.DataItem, "UserID") %>" title="Send <%# DataBinder.Eval(Container.DataItem, "UserName") %> an email!"><%# DataBinder.Eval(Container.DataItem, "UserName") %></a> </ItemTemplate> </asp:Datalist>
If you need help, let me know.
![]() |
Similar Threads
- How would I write this asp code to work in PHP (PHP)
- asp code generated as text, needed to be seen as asp code again. databses backup (ASP)
- where to put .asp code into html code (ASP.NET)
- Doesn't check if username or email exits in database properly (ASP.NET)
- How do I get the Description attribute in Windows Media Player using ASP? (ASP)
- HELP -my Date code isnt working (ASP)
- ASP .NET database hit counter (ASP.NET)
- ASP.NET controls in Office 2003 style? (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: focus
- Next Thread: Watermarking images and AJAX,FLASH
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox click commonfunctions compatible confirmationcodegeneration content contenttype courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu dynamically edit expose fill flash flv formatdecimal forms formview gridview homeedition iframe iis javascript jquery listbox login menu microsoft mono mouse mssql multistepregistration news numerical objects opera order panelmasterpagebuttoncontrols radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers






