Click here to Skip to main content
15,891,905 members
Home / Discussions / ASP.NET
   

ASP.NET

 
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 
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 
hello again
see,my problem exactly is that my program without putting the ScriptManagerProxy hasn't any problem and works properly.but with it doesn't work.
"doesn't work" is in other word,not that my program has an error,no,only works bad.(i haven't a syntax error while have a runtime error only and only for the ScriptManagerProxy tag )

for more explanations:

in the code below,if we haven't ScriptManagerProxy tag in the page,we can to enter the values in the fiels and press the button to sends the values.but if we put ScriptManagerProxy tag in the page,the program isn't able to send the values because says FileUpload1.HasFile is false (fileupload1 is empty)then the if condition isn't true therefore my Query doesn't run.i hope to explain properly.
C#
<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:Button ID="btnAddProductions" runat="server" Text="add productions" onclick="btnAddProductions_Click" />
       <!------------------------------------------------------------------------>
       <asp:Label ID="lblResult" runat="server" ForeColor="Red"></asp:Label>
       <br />
       <asp:ValidationSummary ID="ValidationSummary1" runat="server" />



in this code behind file in below,the running of the query is dependent to correctness fileOK variable.
therefore first must FileUpload1.HasFile be true.
when the program runs,and i fill the fields and press the button,the program jumps on "else" and runs
lblResult.Text="the format of the image isn't true";
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 = "the new production is registered";
            cn.Close();
        }
        else
        {
            lblResult.Text = "the format of the image isn't true";
        }
        //-----------------------------------------------------------

    }//btnAddProductions_Click
}


modified 2-Jan-14 8:22am.

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 
QuestionAsp.net: Count number of records in sql table Pin
Otekpo Emmanuel28-Dec-13 4:13
Otekpo Emmanuel28-Dec-13 4:13 
AnswerRe: Asp.net: Count number of records in sql table Pin
Peter Leow28-Dec-13 4:29
professionalPeter Leow28-Dec-13 4:29 
GeneralRe: Asp.net: Count number of records in sql table Pin
Otekpo Emmanuel28-Dec-13 6:32
Otekpo Emmanuel28-Dec-13 6:32 
GeneralRe: Asp.net: Count number of records in sql table Pin
Peter Leow28-Dec-13 7:33
professionalPeter Leow28-Dec-13 7: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.