Click here to Skip to main content
15,889,867 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: i need to have basic codes to create a website Pin
Peter Leow1-Jan-14 19:21
professionalPeter Leow1-Jan-14 19:21 
AnswerRe: i need to have basic codes to create a website Pin
thatraja1-Jan-14 19:54
professionalthatraja1-Jan-14 19:54 
GeneralI second this recommendation. Pin
David C# Hobbyist.3-Jan-14 12:05
professionalDavid C# Hobbyist.3-Jan-14 12:05 
AnswerRe: i need to have basic codes to create a website Pin
ZurdoDev3-Jan-14 3:33
professionalZurdoDev3-Jan-14 3:33 
AnswerRe: i need to have basic codes to create a website Pin
Harikrishnanvr7-Jan-14 5:26
professionalHarikrishnanvr7-Jan-14 5:26 
Questiona problem with ScriptManagerProxy Pin
Ya Rasoolallah1-Jan-14 11:31
Ya Rasoolallah1-Jan-14 11:31 
AnswerRe: a problem with ScriptManagerProxy Pin
Marco Bertschi1-Jan-14 12:24
protectorMarco Bertschi1-Jan-14 12:24 
AnswerRe: a problem with ScriptManagerProxy Pin
Ya Rasoolallah1-Jan-14 12:40
Ya Rasoolallah1-Jan-14 12:40 
OK!


the .aspx page

C#
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


<%@ Register src="admin/productions.ascx" tagname="Product" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        
        
    <uc1:Product ID="Product1" runat="server" />
    </div>
    
    </form>
</body>
</html>




the .ascx page

C#
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Productions.ascx.cs" Inherits="Admin_Productions" %>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Configuration"%>
<!--------------------------------------------------->
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>



<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<!--------------------------------------------------->
<div align="center">
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
        DataSourceID="SqlDataSource1" DataTextField="CategoryName" 
        DataValueField="CategoryID">
    </asp:DropDownList><br /><br />
    <!--------------------------------------------------->
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        SelectCommand="SELECT * FROM [tbl_ProductCategory]"></asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
        BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
        DataKeyNames="ProductionID" DataSourceID="SqlDataSource2" >
              <EmptyDataTemplate>
              در این دسته بندی داده ای نیست
              </EmptyDataTemplate>
       
        <RowStyle BackColor="White" ForeColor="#003399" />
        <Columns>
            <asp:CommandField CancelText="انصراف" DeleteText="حذف" EditText="ویرایش" 
                HeaderText="عملیات" ShowDeleteButton="True" ShowEditButton="True" 
                UpdateText="بروز رسانی" />
            <asp:BoundField DataField="ProductionID" HeaderText="ای دی محصول" 
                InsertVisible="False" ReadOnly="True" SortExpression="ProductionID" />
                <asp:TemplateField HeaderText="ای دی دسته بندی محصول" 
                SortExpression="ProductionCategoryID">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" 
                            Text='<%# Bind("ProductionCategoryID") %>' Enabled="false"></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" 
                            Text='<%# Bind("ProductionCategoryID") %>'></asp:Label>
                    </ItemTemplate>
                    
            </asp:TemplateField>
                 
                               
            <asp:BoundField DataField="ProductionName" HeaderText="نام محصول" 
                SortExpression="ProductionName" />
            <asp:BoundField DataField="Cast" HeaderText="قیمت به تومان" 
                SortExpression="Cast" />
            <%--<asp:BoundField DataField="ImageFilm" HeaderText="عکس یا فیلم" 
                SortExpression="ImageFilm" />--%>
                
            <asp:TemplateField HeaderText="عکس یا فیلم" SortExpression="ImageFilm">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("ImageFilm") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Image ID="Image1" runat="server" Height="75px" Width="75px" ImageUrl='<%# Bind("ImageFilm") %>'/>
                </ItemTemplate>
            </asp:TemplateField>
                
            <asp:BoundField DataField="Comments" HeaderText="توضیحات" 
                SortExpression="Comments" />
            <asp:BoundField DataField="Stock" HeaderText="موجودی" SortExpression="Stock" />
            
        </Columns>
        <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
        <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
        <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
        <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
    </asp:GridView>
    <br /><!--------------------------------------------------->
    <br />
    <div dir="rtl">
    <%--<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="ProductionID" DataSourceID="SqlDataSource2" Height="50px" 
         Width="702px" oniteminserted="DetailsView1_ItemInserted" 
            oniteminserting="DetailsView1_ItemInserting">
         
        <Fields>
        
            <asp:BoundField DataField="ProductionID" HeaderText="آی دی محصول" 
                InsertVisible="False" ReadOnly="True" SortExpression="ProductionID" 
                Visible="False" />
                
            <asp:BoundField DataField="ProductionCategoryID" 
                HeaderText="آی دی دسته بندی محصول" SortExpression="ProductionCategoryID" />
                           
            <asp:BoundField DataField="ProductionName" HeaderText="نام محصول" 
                SortExpression="ProductionName" />
            <asp:BoundField DataField="Cast" HeaderText="قیمت به تومان" 
                SortExpression="Cast" />
                <asp:TemplateField HeaderText="عکس یا فیلم" SortExpression="ImageFilm">
                <ItemTemplate>
                <asp:FileUpload runat="server" ID="fileUp" />
                </ItemTemplate>
                </asp:TemplateField>
            <asp:BoundField DataField="Stock" HeaderText="موجودی" SortExpression="Stock" />
            <asp:CommandField CancelText="انصراف" InsertText="درج شود" NewText="درج" 
                ShowInsertButton="True" HeaderText="عملیات" />
            
        </Fields>
        
    </asp:DetailsView>
    --%>    <br />
        <table class="style1">
            <tr>
                <td>
                    <asp:Label ID="Label2" runat="server" Text="ای دی دسته بندی محصول"></asp:Label>
                </td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
                        DataSourceID="SqlDataSource1" DataTextField="CategoryName" 
                        DataValueField="CategoryID">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label3" runat="server" Text="نام محصول"></asp:Label>
                </td>
                <td>
                <asp:TextBox ID="txtProName" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="txtProName" Display="Dynamic" 
                        ErrorMessage="نام محصول را وارد نکرده اید" SetFocusOnError="True">*</asp:RequiredFieldValidator>
                 </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label4" runat="server" Text="قیمت"></asp:Label>
                </td>
                <td>
                <asp:TextBox ID="txtCast" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="txtCast" Display="Dynamic" 
                        ErrorMessage="قیمت را وارد نکرده اید" SetFocusOnError="True">*</asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label5" runat="server" Text="عکس یا فیلم"></asp:Label>
                </td>
                <td>
                    <asp:FileUpload ID="FileUpload1" runat="server" />
                 </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label6" runat="server" Text="توضیحات"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtComment" runat="server" TextMode="MultiLine"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                        ControlToValidate="txtComment" Display="Dynamic" 
                        ErrorMessage="توضیحات را وارد نکرده اید" SetFocusOnError="True">*</asp:RequiredFieldValidator>
                 </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="موجودی"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtStock" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                        ControlToValidate="txtStock" Display="Dynamic" 
                        ErrorMessage="موجودی را وارد نکرده اید" SetFocusOnError="True">*</asp:RequiredFieldValidator>
                </td>
            </tr>
        </table>
        <br />
        <!---------------------->
       <%-- <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
       --%>       
        <%--<asp:HtmlEditorExtender  ID="HtmlEditorExtender1" runat="server" TargetControlID="txtComment">
        </asp:HtmlEditorExtender>--%>
        <!------------------------------------------------------------------------>
        
        
        <asp:Button ID="btnAddProductions" runat="server" Text="اضافه کردن محصولات" 
            onclick="btnAddProductions_Click" />
        <!------------------------------------------------------------------------>
        <asp:Label ID="lblResult" runat="server" ForeColor="Red"></asp:Label>
        <br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
    </div>
    </div>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConflictDetection="CompareAllValues" 
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        DeleteCommand="DELETE FROM [tbl_Production] WHERE [ProductionID] = @original_ProductionID AND [ProductionCategoryID] = @original_ProductionCategoryID AND [ProductionName] = @original_ProductionName AND [Cast] = @original_Cast AND [ImageFilm] = @original_ImageFilm AND [Comments] = @original_Comments AND [Stock] = @original_Stock" 
        InsertCommand="INSERT INTO [tbl_Production] ([ProductionCategoryID], [ProductionName], [Cast], [ImageFilm], [Comments], [Stock]) VALUES (@ProductionCategoryID, @ProductionName, <a href="/Members/cast">@Cast</a> @ImageFilm, @Comments, <a href="/Members/stock">@Stock</a>" 
        OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT * FROM [tbl_Production] WHERE ([ProductionCategoryID] = @ProductionCategoryID)" 
        UpdateCommand="UPDATE [tbl_Production] SET [ProductionCategoryID] = @ProductionCategoryID, [ProductionName] = @ProductionName, [Cast] = <a href="/Members/cast">@Cast</a> [ImageFilm] = @ImageFilm, [Comments] = @Comments, [Stock] = <a href="/Members/stock">@Stock</a>WHERE [ProductionID] = @original_ProductionID AND [ProductionCategoryID] = @original_ProductionCategoryID AND [ProductionName] = @original_ProductionName AND [Cast] = @original_Cast AND [ImageFilm] = @original_ImageFilm AND [Comments] = @original_Comments AND [Stock] = @original_Stock">
        <SelectParameters>
            <asp:ControlParameter ControlID="DropDownList1" Name="ProductionCategoryID" 
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="original_ProductionID" Type="Int32" />
            <asp:Parameter Name="original_ProductionCategoryID" Type="Int32" />
            <asp:Parameter Name="original_ProductionName" Type="String" />
            <asp:Parameter Name="original_Cast" Type="Decimal" />
            <asp:Parameter Name="original_ImageFilm" Type="String" />
            <asp:Parameter Name="original_Comments" Type="String" />
            <asp:Parameter Name="original_Stock" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="ProductionCategoryID" Type="Int32"/>
            <asp:Parameter Name="ProductionName" Type="String" />
            <asp:Parameter Name="Cast" Type="Decimal" />
            <asp:Parameter Name="ImageFilm" Type="String" />
            <asp:Parameter Name="Comments" Type="String" />
            <asp:Parameter Name="Stock" Type="Int32" />
            <asp:Parameter Name="original_ProductionID" Type="Int32" />
            <asp:Parameter Name="original_ProductionCategoryID" Type="Int32" />
            <asp:Parameter Name="original_ProductionName" Type="String" />
            <asp:Parameter Name="original_Cast" Type="Decimal" />
            <asp:Parameter Name="original_ImageFilm" Type="String" />
            <asp:Parameter Name="original_Comments" Type="String" />
            <asp:Parameter Name="original_Stock" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="ProductionCategoryID" Type="Int32" />
            <asp:Parameter Name="ProductionName" Type="String" Size="100"/>
            <asp:Parameter Name="Cast" Type="Decimal" />
            <asp:Parameter Name="ImageFilm" Type="String" Size="100"/>
            <asp:Parameter Name="Comments" Type="String" />
            <asp:Parameter Name="Stock" Type="Int32" />
        </InsertParameters>
    </asp:SqlDataSource>
    <!--------------------------------------------------->
</ContentTemplate>
</asp:UpdatePanel>
<!--------------------------------------------------->


the .ascx.cs page

C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
public partial class Admin_Productions : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        

    }

    protected void btnAddProductions_Click(object sender, EventArgs e)
    {
        //-----------------------------------------------------------
        bool fileOK = false;

        string[] allow = { ".jpg", ".jpeg", ".gif", ".bmp", ".png" };
        string fileExtension = Path.GetExtension(FileUpload1.FileName).ToLower().Trim();
        if (FileUpload1.HasFile)
        {
            for (int i = 0; i < allow.Length; i++)
            {
                if (fileExtension == allow[i] && FileUpload1.FileBytes.Length < 1048576)
                {
                    fileOK = true;
                }
            }
        }
        //-----------------------------------------------------------
        if (fileOK==true)
        {
            //FileUpload1.SaveAs(Server.MapPath(Path.Combine("~/images/",FileUpload1.FileName));
            FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/"+FileUpload1.FileName));

            SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
            string query = "insert into tbl_production values (@proCatId,@proName,@proCast,@proPic,@proComment,@proStock)";
            SqlCommand cm = new SqlCommand(query, cn);
            cm.Parameters.AddWithValue("proCatId", DropDownList2.SelectedValue);
            cm.Parameters.AddWithValue("proName", txtProName.Text.Trim().ToLower());
            cm.Parameters.AddWithValue("proCast", txtCast.Text.Trim());
            cm.Parameters.AddWithValue("proPic", "~/images/"+FileUpload1.FileName.Trim().ToLower());
            cm.Parameters.AddWithValue("proComment", txtComment.Text);
            cm.Parameters.AddWithValue("proStock", txtStock.Text);
            cn.Open();
            cm.ExecuteNonQuery();
            lblResult.Text = "registered";
            cn.Close();
        }
        else
        {
            lblResult.Text = "incorrect";
        }
        //-----------------------------------------------------------

    }//btnAddProductions_Click
}

SuggestionRe: a problem with ScriptManagerProxy Pin
Richard MacCutchan1-Jan-14 22:28
mveRichard MacCutchan1-Jan-14 22:28 
GeneralRe: a problem with ScriptManagerProxy Pin
Ya Rasoolallah1-Jan-14 23:40
Ya Rasoolallah1-Jan-14 23:40 
GeneralRe: a problem with ScriptManagerProxy Pin
Richard MacCutchan2-Jan-14 0:09
mveRichard MacCutchan2-Jan-14 0:09 
AnswerRe: a problem with ScriptManagerProxy Pin
Ya Rasoolallah2-Jan-14 1:48
Ya Rasoolallah2-Jan-14 1:48 
QuestionHow to find curses movement in text box Pin
GurbachanSinghMSc30-Dec-13 22:22
GurbachanSinghMSc30-Dec-13 22:22 
QuestionRe: How to find curses movement in text box Pin
ZurdoDev1-Jan-14 15:31
professionalZurdoDev1-Jan-14 15:31 
Questiondropdownchosen Pin
Ravi900kumar30-Dec-13 19:45
Ravi900kumar30-Dec-13 19:45 
AnswerRe: dropdownchosen Pin
Tom Marvolo Riddle30-Dec-13 20:02
professionalTom Marvolo Riddle30-Dec-13 20:02 
QuestionRe: dropdownchosen Pin
ZurdoDev1-Jan-14 15:31
professionalZurdoDev1-Jan-14 15:31 
AnswerRe: dropdownchosen Pin
Karthik_Mahalingam4-Jan-14 11:40
professionalKarthik_Mahalingam4-Jan-14 11:40 
QuestionAsp.net panel control Pin
Otekpo Emmanuel30-Dec-13 13:27
Otekpo Emmanuel30-Dec-13 13:27 
Questionscafolding Pin
Member 1049405229-Dec-13 19:59
Member 1049405229-Dec-13 19:59 
AnswerRe: scafolding Pin
thatraja29-Dec-13 23:17
professionalthatraja29-Dec-13 23:17 
QuestionASP.NET or ASP.NET MVC Pin
Ger Hayden29-Dec-13 9:52
Ger Hayden29-Dec-13 9:52 
AnswerRe: ASP.NET or ASP.NET MVC Pin
thatraja29-Dec-13 16:38
professionalthatraja29-Dec-13 16:38 
QuestionAsp.net: upload zip files and download Pin
Otekpo Emmanuel28-Dec-13 12:46
Otekpo Emmanuel28-Dec-13 12:46 
QuestionRe: Asp.net: upload zip files and download Pin
ZurdoDev1-Jan-14 15:33
professionalZurdoDev1-Jan-14 15:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.