无效的回发或回调参数.使用以下方式启用事件验证 [英] Invalid postback or callback argument. Event validation is enabled using

查看:78
本文介绍了无效的回发或回调参数.使用以下方式启用事件验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我已使用Web服务将大陆,国家和城市的绑定下拉列表.
而且我必须提交一个表格以将数据插入数据库.
现在出现错误.

无效的回发或回调参数.使用< pages enableeventvalidation ="true">启用事件验证.在配置中或<%@页面EnableEventValidation ="true"%>在页面中.为了安全起见,此功能验证回发或回调事件的参数源自最初呈现它们的服务器控件.如果数据有效且预期,请使用ClientScriptManager.RegisterForEventValidation方法以注册回发或回调数据以进行验证.

在我的网络服务页面中
------------------------

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
------------------------

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();
        
    }




并在我的Hotels.aspx页面中
------------------------------




and in my Hotels.aspx page
------------------------------

<%@ 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
----------------------




---------------------------------
and in my Hotels.axpx.cs page
----------------------

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.
请帮助

Thanking you in advance


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

Thanking you in advance

推荐答案

Now, there could be few reasons why you are getting this issue.简单/直接的解决方案可以在您的Page指令或Web.config文件中添加enableEventValidation="false".


有趣的是阅读一个与此相关的博客条目: [
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.


这篇关于无效的回发或回调参数.使用以下方式启用事件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆