{"id":329,"date":"2007-08-25T12:36:35","date_gmt":"2007-08-25T11:36:35","guid":{"rendered":"http:\/\/soci.hu\/blog\/index.php\/2007\/08\/25\/az-aljas-xmldatasource-cacheles\/"},"modified":"2007-12-12T16:46:25","modified_gmt":"2007-12-12T15:46:25","slug":"az-aljas-xmldatasource-cacheles","status":"publish","type":"post","link":"https:\/\/soci.hu\/blog\/index.php\/2007\/08\/25\/az-aljas-xmldatasource-cacheles\/","title":{"rendered":"Az aljas XmlDataSource cachel\u00e9s"},"content":{"rendered":"<p>Az egyik kedves ismer\u0151s\u00f6m keresett meg egy probl\u00e9m\u00e1val, amiben v\u00e9letlenszer\u0171en gond volt egy DataBind-olt DropDownList-tel.<\/p>\n<p>Kicsit k\u00f6rbej\u00e1rva a probl\u00e9m\u00e1t kider\u00fclt, hogy az XmlDataSource alapban cache-el kem\u00e9nyen, ami statikus XML f\u00e1jlok eset\u00e9n nem lenne nagy gond, s\u0151t, de dinamikus bemenetn\u00e9l alattomos hib\u00e1kat okozhat.<br \/>\nAz al\u00e1bbi k\u00f3dot p\u00e1rszor futtatva azonnal l\u00e1tszik a cache-el\u00e9s okozta hiba, m\u00edg a xds.EnableCaching = false; sor hat\u00e1s\u00e1ra megsz\u0171nik.<\/p>\n<p>[source:xhtml]<br \/>\n<%@ Page Language=\"C#\" AutoEventWireup=\"true\" \nCodeFile=\"Default.aspx.cs\" Inherits=\"_Default\" %><\/p>\n<p><!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN\" \n\"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd\"><br \/>\n<html xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><br \/>\n<head runat=\"server\"><br \/>\n\t<title>Untitled Page<\/title><br \/>\n<\/head><br \/>\n<body><\/p>\n<form id=\"form1\" runat=\"server\">\n<div>\n\t\t\t<asp:DropDownList ID=\"ize\" runat=\"server\" \n\t\t\t\tCssClass=\"middle\" DataTextField=\"Azonosito\"\n\t\t\t\tDataValueField=\"Kod\"><br \/>\n\t\t\t<\/asp:DropDownList>\n\t\t<\/div><\/form>\n<p><\/body><br \/>\n<\/html><br \/>\n[\/source]<\/p>\n<p>[source:csharp]<br \/>\nusing System;<br \/>\nusing System.Web.UI;<br \/>\nusing System.Web.UI.WebControls;<\/p>\n<p>public partial class _Default : System.Web.UI.Page<br \/>\n{<br \/>\n    int a;<br \/>\n    string[] gy = { &#8220;alma&#8221;, &#8220;korte&#8221; };<\/p>\n<p>    protected void Page_Load(object sender, EventArgs e)<br \/>\n    {<br \/>\n        XmlDataSource xds = new XmlDataSource();<br \/>\n        \/\/xds.EnableCaching = false;<br \/>\n        this.Controls.Add(xds);<br \/>\n        xds.ID = &#8220;d&#8221;;<br \/>\n        a = new Random().Next(0, 2);<\/p>\n<p>        xds.Data = string.Format(<br \/>\n        @&#8221;<Data><br \/>\n            <Row Kod='{0}' Azonosito='{1}' \/><br \/>\n            <Row Kod='2' Azonosito='barack' \/><br \/>\n        <\/Data>&#8220;,<br \/>\n        a, gy[a]);<br \/>\n        xds.XPath = &#8220;Data\/Row&#8221;;<br \/>\n        ize.DataSourceID = &#8220;d&#8221;;<br \/>\n    }<\/p>\n<p>    protected override void Render(HtmlTextWriter writer)<br \/>\n    {<br \/>\n        base.Render(writer);<\/p>\n<p>        int b = int.Parse(ize.Items[0].Value);<br \/>\n        if (b != a)<br \/>\n        {<br \/>\n            throw new InvalidOperationException(<br \/>\n                string.Format(<br \/>\n                &#8220;Baj van, elv\u00e1rt \u00e9rt\u00e9k a lista els\u0151 elem\u00e9ben: {0}, t\u00e9nyleges: {1}&#8221;,<br \/>\n                a, b));<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>[\/source]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Az egyik kedves ismer\u0151s\u00f6m keresett meg egy probl\u00e9m\u00e1val, amiben v\u00e9letlenszer\u0171en gond volt egy DataBind-olt DropDownList-tel. Kicsit k\u00f6rbej\u00e1rva a probl\u00e9m\u00e1t kider\u00fclt, hogy az&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,14,10,4],"tags":[],"class_list":["post-329","post","type-post","status-publish","format-standard","hentry","category-net","category-aspnet","category-c","category-szakmai-elet"],"_links":{"self":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":0,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"wp:attachment":[{"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/soci.hu\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}