Tuesday, May 5, 2015

Dynamic Button Asp.net

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        SQLSTR = ""
        SQLSTR = " SELECT  [ID],[MENU] FROM [CMS_MENU]"
        DSC = GetDS(SQLSTR)
      

            count = Convert.ToInt32(DSC.Tables(0).Rows.Count)

            For i As Integer = 0 To count - 1
            'specifying the condition in for loop for creating no. of textboxes
            'Create the object of TexBox Class
            bt1.ID = ""
            Dim bt As New Button()
            bt.ID = DSC.Tables(0).Rows(i)("ID").ToString
            bt.Text = DSC.Tables(0).Rows(i)("MENU").ToString
            bt.CssClass = "submit1"
            bt1.ID = bt.ID
            AddHandler bt.Click, AddressOf info
            Form.Controls.Add(bt)

            Next
    
    End Sub

    Public Function info(ByVal sender As Object, ByVal e As EventArgs)
        Dim bttoclicked As Button = TryCast(sender, Button)
        If bttoclicked IsNot Nothing Then
            menu = bttoclicked.Text
            If menu = "RENT" Then
                Response.Redirect("Child_Main.aspx")
            ElseIf menu = "LEASE" Then
                Response.Redirect("Child2_Main.aspx")
            End If
        End If
        Return menu
    End Function

Wednesday, July 16, 2014

How to Create a Nice and Simple Flash Website

Steps

  1. 1
    Open your Macromedia Flash and click on Flash Document in Create new category.
  2. 2
    Press "v" and click on the grey space , then in the Properties click on Size:550 x 400 pixels button on the top of the Publish: settings . If the Properties windows is not open, Press Ctrl + F3 or go to window\Properties\Properties and check it.
  3. 3
    Change your workspace size to 800 X 600 and press OK.
  4. 4
    Now We're gonna set a background for our Website:
    • Create a Layer and name it as background-image (the name is Optimal and you can any name you want) - check the tips if you don't know how.
    • Press Ctrl + R to insert your image or go to Files \ Import \ Import to library and the drag it to your stage.
    • Remember that your background image must be in 800 X 600.
    • Put your image's location on x=0 , y=0 to fit it on the stage.
    • As we have nothing to do with this layer from now... lock it. (Click on the dot which is under the lock image in the Timeline window.)
      • Note that to change your image size, open it with Photoshop, Press Ctrl + Alt + I then disable the Constrain Proportions and change your image size to 800 X 600 Pixels.(more in Tips and warnings sections)
  5. 5
    Create the button for your website's parts.
  6. 6
    Open your Photoshop and do the following:
    • Create a new image in 120 X 120
    • Press "W" and click on stage.
    • Press click on Eraser, then Right click on it and choose "Background Eraser tool"
    • Erase the whole stage.
    • Choose the shape tool then right click on it and choose "Rounded Rectangle Tool".
    • Create a shape on your stage and change the color to black. (The color is Optimal).
  7. 7
    Put highlights on the button open your Photoshop and do the following:
    • Click on the stage and OK the Massage.
    • Press "M" and make a rectangle which take the half of our button.
    • click on Gradient tool , if it's on Paint Bucket tool , right click on it and change it to Gradient tool.
    • Change the Opacity to 17%.
    • Choose the white color.( some color which is antonym with Black or color you have chosen)
    • Now color the rectangle with the Gradient tool for once or twice.
    • press "M" and click on stage to dis select the rectangle.
    • Press Ctrl + Shift + S and Save your file in .PNG format.
  8. 8
    Button.png
    My Button: ( don't add text, we will add it in Macromedia Flash)
  9. 9
    Add the buttons to your work:
    • Go back to Macromedia Flash
    • Create a Layer (top of the Background , other wise the content of the Layer will not show) and name it "button" ( The name is optimal)
    • Press Ctrl + R to import the button for the first time after that the image will be saved into your library and you can drag it from library to stage.
    • I have inserted 5 buttons
    • Set the location of buttons as : Y=18(for All buttons) and x= 137.0 - 244,0 - 351,0 - 458,0 -565,0
  10. 10
    Now we have to add the text:
    • Press "t".
    • Choose your Font Face.(like Arial)
    • Choose your Font size as 20.
    • The Choices are optimal.Chosen by me (Home, Downloads, Wallpapers, About us, Contact us)
    • Set the location of each text as : y= 64 (for all) , x= 280 - 170,0 - 385,0 - 489,0 - 600
  11. Ex1.jpg
    11
    To test your work press Ctrl + Enter
  12. 12
    We are gonna make these buttons change to anther color when we bring mouse over them.
    • First we need to create another button as pressed in Photoshop.
    • Open your button.
    • Press "M"
    • Select all your button.
    • choose the normal brush and change the Opacity to 80%.
    • Change the color of your brush to Black and color the whole button for twice.
    • Press Ctrl + Shift + S and save it as Pressed in .PNG format.
  13. 13
    Go back to your Macromedia:
    • Create a new Layer in the top of the Button Layer.
    • Insert the Pressed buttons to your stage and give them the same location as buttons which you have inserted.
    • add the texts and give them the same locations as the texts which you have created. you can also cope & paste them too(only for text)
  14. 14
    Make buttons useful:
    • Choose your pressed button.
    • Right click on it.
    • Choose "convert to Symbol"
    • Choose button and the name of symbol is up to you!
    • Press OK
    • double click on your symbol.
    • drag the Keyframe from "UP" to "Over".
    • double click on stage to get back.
    • Do this for all buttons.
  15. 15
    Now we're gonna give this button links.
    • Open the "Behavior window" by pressing "Shift + F3"
    • Now click on your button ( pressed button which is in some kinda blue color).
    • As you have selected the button , click on the Blue Plus button in the Behavior window.
    • Choose "Web" from list and write your link.
    • You can also choose the window open in which window.(_blank, _same, ...)
    • Open the scripting windows and change release to press.
    • Do this for all the buttons.
  16. 16
    Now let's make our website look better.
    • Go to your Photoshop
    • Create a new image in 548 X 320
    • Erase the background
    • Choose the paint bucket tool and set the Opacity as 44% and change the color to black.
    • Fill the background for twice or once.
    • Save it as .PNG
    • Create a new layer on the top of the all layers.
    • Now add it to your Work in this location: x=137 , y=138 px
    • Write your content on it.
  17. Ex2.jpg
    17
  18. 18
    This Step is important.
    • Create a new Layer on the top of all layers. Whether if you want to add a new layer must be under the layer.
    • As you know you have to add a keyframe for each website page.
    • Add nothing to this layer and keep it empty
    • on this layer add empty keyframe on the keyframes which contains your pages.
    • Add this script to your empty keyframes: stop(); ( click on the keyframe , on the properties windows , clock on the arrow which is on the question mark)
  19. 19
    Do the final designs:
    • In Macromedia flash
    • Choose rectangle tool.
    • delete the border.( Click on the pencil then click on no color)
    • set Fill color as Black.
    • Make your rectangle
    • Change w to 800 and h to 100.
    • set the position as [x=0,y=500]
  20. 20
    You could also add some other images and website's logo and some texts like privacy, .... to your website.
  21. 21
    Now it's time to publish our website.
    • Press "V" and click on the grey stage.
    • Choose "Publish settings".
    • On the window which appear choose "Formats" on the top of the window.
    • Check the ".HTML" .
    • Click on "Publish"
  22. 22
    Now you have published your HTML page. We have to make this website to fit to any screen.
  23. 23
    Replace the red codes with the previous code:
  24. Finish 1.jpg
    24
    Finish

Monday, May 20, 2013

Repeater Control example in asp.net

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Repeator Control Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Enter Name: </td>
<td><asp:TextBox ID="txtName" runat="server"/></td>
</tr>
<tr>
<td>Enter Subject: </td>
<td><asp:TextBox ID="txtSubject" runat="server"/></td>
</tr>
<tr>
<td valign="top">Enter Comments:</td>
<td><asp:TextBox ID="txtComment" runat="server" Rows="5" Columns="20" TextMode="MultiLine"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" /></td>
</tr>
</table>
</div>
<div>
<asp:Repeater ID="RepDetails" runat="server">
<HeaderTemplate>
<table style=" border:1px solid #df5015; width:500px" cellpadding="0">
<tr style="background-color:#df5015; color:White">
<td colspan="2">
<b>Comments</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#EBEFF0">
<td>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015; width:500px" >
<tr>
<td>
Subject:
<asp:Label ID="lblSubject" runat="server" Text='<%#Eval("Subject") %>' Font-Bold="true"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("Comment") %>'/>
</td>
</tr>
<tr>
<td>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015;border-bottom:1px solid #df5015; width:500px" >
<tr>
<td>Post By: <asp:Label ID="lblUser" runat="server" Font-Bold="true" Text='<%#Eval("UserName") %>'/></td>
<td>Created Date:<asp:Label ID="lblDate" runat="server" Font-Bold="true" Text='<%#Eval("PostedDate") %>'/></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
After completion of aspx page design add following namespaces in code behind

C# Code

using System;
using System.Data;
using System.Data.SqlClient;
After add namespace write the following code


private SqlConnection con = new SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true");
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindRepeaterData();
}
}
// This button click event is used to insert comment details and bind data to repeater control
protected void btnSubmit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into Repeater_Table (UserName,Subject,Comment,PostedDate) values(@userName,@subject,@comment,@postedDate)", con);
cmd.Parameters.AddWithValue("@userName", txtName.Text);
cmd.Parameters.AddWithValue("@subject", txtSubject.Text);
cmd.Parameters.AddWithValue("@comment", txtComment.Text);
cmd.Parameters.AddWithValue("@postedDate", DateTime.Now);
cmd.ExecuteNonQuery();
con.Close();
txtName.Text = string.Empty;
txtSubject.Text = string.Empty;
txtComment.Text = string.Empty;
BindRepeaterData();
}
//Bind Data to Repeater Control
protected void BindRepeaterData()
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from Repeater_Table Order By PostedDate desc", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
RepDetails.DataSource = ds;
RepDetails.DataBind();
con.Close();
}
VB.NET Code

Imports System.Data
Imports System.Data.SqlClient

Partial Public Class Default2
Inherits System.Web.UI.Page
Private con As New SqlConnection("Data Source=SureshDasari;Initial Catalog=MySampleDB;Integrated Security=true")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindRepeaterData()
End If
End Sub
' This button click event is used to insert comment details and bind data to repeater control
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
con.Open()
Dim cmd As New SqlCommand("insert into Repeater_Table (UserName,Subject,Comment,PostedDate) values(@userName,@subject,@comment,@postedDate)", con)
cmd.Parameters.AddWithValue("@userName", txtName.Text)
cmd.Parameters.AddWithValue("@subject", txtSubject.Text)
cmd.Parameters.AddWithValue("@comment", txtComment.Text)
cmd.Parameters.AddWithValue("@postedDate", DateTime.Now)
cmd.ExecuteNonQuery()
con.Close()
txtName.Text = String.Empty
txtSubject.Text = String.Empty
txtComment.Text = String.Empty
BindRepeaterData()
End Sub
'Bind Data to Repeater Control
Protected Sub BindRepeaterData()
con.Open()
Dim cmd As New SqlCommand("select * from Repeater_Table Order By PostedDate desc", con)
Dim ds As New DataSet()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
RepDetails.Visible = True
RepDetails.DataSource = ds
RepDetails.DataBind()
Else
RepDetails.Visible = False
End If
con.Close()
End Sub
End Class