Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i have used webservices for bind dropdown for the continent,country,and city.
and i have to submit a form for insert the data into database.
now it giving the error.

Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true"> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

in my webservices page
------------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using AjaxControlToolkit;
using BusinessLogicsTourismLeads.AdminBusiness;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Collections.Specialized;


/// <summary>
/// Summary description for CascadingDropdown
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
[System.Web.Script.Services.ScriptService()]
public class CascadingDropdown : System.Web.Services.WebService {
    private static string strconnection = "Data Source=.; Initial catalog=TOURISMLEADS; USER ID=sa; Password=123;";
    SqlConnection concountry = new SqlConnection(strconnection);

    public CascadingDropdown () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    AdminBusinessLogic abl = new AdminBusinessLogic();
    
    [WebMethod]
    public CascadingDropDownNameValue[] BindContinentDetails(string knownCategoryValues, string category)
    {
        concountry.Open();
        //string strQuery = "select ContinentalID, ContinentalName from TblContinental";
        //System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strQuery);
        //abl.DisplayContinent(strQuery);
        SqlCommand cmdcontinent = new SqlCommand("select ContinentalID, ContinentalName from TblContinental", concountry);
        cmdcontinent.ExecuteNonQuery();
        SqlDataAdapter dacontinent = new SqlDataAdapter(cmdcontinent);
        DataSet dscontinent = new DataSet();
        dacontinent.Fill(dscontinent);
        concountry.Close();
        List<cascadingdropdownnamevalue> contidetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtrow in dscontinent.Tables[0].Rows)
        {
            string ContinentalID = dtrow["ContinentalID"].ToString();
            string ContinentalName = dtrow["ContinentalName"].ToString();
            contidetails.Add(new CascadingDropDownNameValue(ContinentalName, ContinentalID));
        }
        return contidetails.ToArray();
     }
    [WebMethod]
    public CascadingDropDownNameValue[] BindCountryDetails(string knownCategoryValues, string category)
    {
        int ContinentalID;
        //This method will return a StringDictionary containing the name/value pairs of the currently selected values
        StringDictionary continentdetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        ContinentalID = Convert.ToInt32(continentdetails["Continent"]);

        concountry.Open();
        SqlCommand cmdCountry = new SqlCommand("SELECT COUNTRYID,COUNTRYNAME FROM TBLCOUNTRY where ContinentalID=@ContinentalID", concountry);
        cmdCountry.Parameters.AddWithValue("@ContinentalID",ContinentalID);
        cmdCountry.ExecuteNonQuery();
        SqlDataAdapter dacountry = new SqlDataAdapter(cmdCountry);
        DataSet dscountry = new DataSet();
        dacountry.Fill(dscountry);
        concountry.Close();
        //create list and add items in it by looping through dataset table
        List<cascadingdropdownnamevalue> countrydetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtrow in dscountry.Tables[0].Rows)
        {
            string CountryID = dtrow["CountryID"].ToString();
            string CountryName = dtrow["CountryName"].ToString();
            countrydetails.Add(new CascadingDropDownNameValue(CountryName, CountryID));
        }
        return countrydetails.ToArray();
    }
    [WebMethod]
    public CascadingDropDownNameValue[] BindCityDetails(string knownCategoryValues, string category)
    {
        int CountryID;
        StringDictionary countrydetails = AjaxControlToolkit.CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
        CountryID = Convert.ToInt32(countrydetails["Country"]);

        concountry.Open();
        SqlCommand cmdCity = new SqlCommand("select PlaceID,placeName from TblTouristPlace where COUNTRYID=@CountryID", concountry);
        cmdCity.Parameters.AddWithValue("@CountryID", CountryID);
        cmdCity.ExecuteNonQuery();
        SqlDataAdapter dacity = new SqlDataAdapter(cmdCity);
        DataSet dscity = new DataSet();
        dacity.Fill(dscity);
        concountry.Close();
        List<cascadingdropdownnamevalue> citydetails = new List<cascadingdropdownnamevalue>();
        foreach (DataRow dtrow in dscity.Tables[0].Rows)
        {
            string PlaceID = dtrow["PlaceID"].ToString();
            string placeName = dtrow["placeName"].ToString();
            citydetails.Add(new CascadingDropDownNameValue(placeName, PlaceID));
        }
        return citydetails.ToArray();

    }
        
        //ddlContinent.DataSource = abl.DisplayContinent(strQuery);
        //ddlContinent.DataTextField = "_CONTINENTNAME";
        //ddlContinent.DataValueField = "_CONTINENTID";
        //ddlContinent.DataBind();
        
    }



and in my Hotels.aspx page
------------------------------
XML
<%@ Page Title="" Language="C#" MasterPageFile="~/Administrator/AdminMasterPage.master" AutoEventWireup="true" CodeFile="Hotels.aspx.cs"
 Inherits="Administrator_Hotels" %>
<%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="Css/AdminControlStyleSheet.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <div>
        <div class="line">
            <div class="label">
                Continent
            </div>
            <div class="text">
                <asp:DropDownList ID="ddlContinent" runat="server"></asp:DropDownList>
                <ajax:CascadingDropDown ID="ccdContinent" runat="server" Category="continent" TargetControlID="ddlContinent"
                 PromptText="select Continent" LoadingText="Loading Continents..." ServiceMethod="BindContinentDetails"
                 ServicePath="CascadingDropdown.asmx"></ajax:CascadingDropDown>

            </div>
        </div>
        <div class="line">
            <div class="label">
                Country
            </div>
            <div class="text">
                <asp:DropDownList ID="ddlCountry" runat="server">
                </asp:DropDownList>
                <ajax:CascadingDropDown ID="ccdCountry" runat="server" Category="Country" ParentControlID="ddlContinent"
                 TargetControlID="ddlCountry" PromptText="Select Country" LoadingText="Loading Country..."
                  ServiceMethod="BindCountryDetails" ServicePath="CascadingDropdown.asmx" ></ajax:CascadingDropDown>
            </div>
        </div>
        <div class="line">
            <div class="label">
                City
            </div>
            <div class="text">
                <asp:DropDownList ID="ddlCity" runat="server"></asp:DropDownList>
                <ajax:CascadingDropDown ID="ccdCity" runat="server" Category="City" ParentControlID="ddlCountry"
                 TargetControlID="ddlCity" PromptText="Select City" LoadingText="Loading City..." ServiceMethod="BindCityDetails"
                  ServicePath="CascadingDropdown.asmx"></ajax:CascadingDropDown>
            </div>
        </div>
        <div class="line">
            <div class="label">

                Hotel Name</div>
            <div class="text">
                <asp:TextBox ID="txtHotelName" runat="server" Text=""></asp:TextBox>
            </div>
        </div>
        <div class="line">
            <div class="label">

                Hotel Image</div>
            <div class="text">
                <asp:FileUpload ID="fuplHotelImage" runat="server" />
                <asp:TextBox ID="txtImageName" runat="server" Text="" Visible="false"></asp:TextBox>
            </div>
        </div>
        <div class="line">
            <div class="label">

                Hotel Star Catagory</div>
            <div class="text">
                <asp:DropDownList ID="ddlHotelStar" runat="server">
                    <asp:ListItem Value="2star.png">2</asp:ListItem>
                    <asp:ListItem Value="3star.png">3</asp:ListItem>
                    <asp:ListItem Value="4star.png">4</asp:ListItem>
                    <asp:ListItem Value="5star.png">5</asp:ListItem>
                    <asp:ListItem Value="1budget.png">Budget Hotel</asp:ListItem>
                </asp:DropDownList>
            </div>
        </div>
        <div class="line">
            <div class="label">

                Address</div>
            <div class="text">
                <asp:TextBox ID="txtAddress" runat="server" Text="" TextMode="MultiLine"></asp:TextBox>
            </div>
        </div>
        <div class="line">
            <div class="label">

                Description</div>
            <div class="text">
                <asp:TextBox ID="txtDescription" runat="server" Text="" TextMode="MultiLine"></asp:TextBox>
            </div>
        </div>
        <div class="line">
            <div class="label">

                Price</div>
            <div class="text">
                <asp:TextBox ID="txtPrice" runat="server" Text=""></asp:TextBox>
            </div>
        </div>
        <div class="line">
            <div class="label">
            Facility
                </div>
            <div class="text">


            </div>
        </div>
        <div class="line" style="text-align:center;">
            <asp:Button ID="btnSubmit" runat="server" Text="Submit"
                onclick="btnSubmit_Click" />
        </div>
    </div>
</asp:Content>



---------------------------------
and in my Hotels.axpx.cs page
----------------------
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using BusinessLogicsTourismLeads.AdminBusiness;

public partial class Administrator_Hotels : System.Web.UI.Page
{
    AdminBusinessLogic abl = new AdminBusinessLogic();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Convert.ToString(Session["username"]) == null)
            {
                Response.Redirect("/TourismLeads/Login.aspx");
            }
            string username = Session["UserName"].ToString();

        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (fuplHotelImage.HasFile)
        {
            string saveLocation = Server.MapPath(@"./HotelstarCatagory");
            string fileExtension = Path.GetExtension(saveLocation);
            string filename = Guid.NewGuid().ToString();
            string savePath = saveLocation + filename + fileExtension;
            txtImageName.Text = filename + fileExtension;
            fuplHotelImage.SaveAs(savePath);
        }
        string strQuery = "insert into TBLHOTELS (CONTINENTALID,COUNTRYID,PLACEID,HOTELNAME,HOTELIMAGE,HOTELCLASS,Description,ADDRESS,PRICE,Created_by,Created_on) values ( " +
        " @CONTINENTALID, @COUNTRYID,@PLACEID,@HOTELNAME,@HOTELIMAGE,@HOTELCLASS,@Description,@ADDRESS,@PRICE,@Created_by,@Created_on) ";
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strQuery);
        cmd.Parameters.Add("@CONTINENTALID", ddlContinent.SelectedValue);
        cmd.Parameters.Add("@COUNTRYID", ddlCountry.SelectedValue);
        cmd.Parameters.Add("@PLACEID", ddlCountry.SelectedValue);
        cmd.Parameters.Add("@HOTELNAME", txtHotelName.Text);
        cmd.Parameters.Add("@HOTELIMAGE", txtImageName.Text);
        cmd.Parameters.Add("@HOTELCLASS", ddlHotelStar.SelectedValue);
        cmd.Parameters.Add("@Description", txtDescription.Text);
        cmd.Parameters.Add("@ADDRESS", txtAddress.Text);
        cmd.Parameters.Add("@PRICE", txtPrice.Text);
        cmd.Parameters.Add("@Created_by", Convert.ToString(Session["username"]));
        cmd.Parameters.Add("@Created_on", DateTime.Now);
        abl.UpdateRecord(strQuery);
        Server.Transfer("~/Administrator/Hotels.aspx");
    }
}

---------------------------------------
sir i am worried for this problem since 2 days.
please help

Thanking you in advance
Posted
Updated 10-Jun-12 23:24pm
v2

1 solution

Now, there could be few reasons why you are getting this issue. Easy/direct solution can be adding enableEventValidation="false" in your Page directive or Web.config file.


Interesting to read one blog entry related to same: “Invalid postback or callback argument” in ASP.NET[^] - It exposes few other reasons on why one can get the same error. Nice read.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900