ye, i know... i need to develop master page for portal that has content like this: //////////////////////////// //div // //Check our latest product! //////////////////////////// //////////////////////////// //div // //Pool: What do you think? //1. //2. //3. //////////////////////////// //////////////////////////// //div // //TOP 1 video //////////////////////////// //////////////////////////// //div // //Latest client activites //////////////////////////// ...many more so i have plenty of "single record" DataSources (queries like "select something from myTable where id=1") the way i did this is: //////////////////////////// //div // // //////////////////////////// //////////////////////////// //div // // //////////////////////////// //////////////////////////// //div // // //////////////////////////// //////////////////////////// //div // // //////////////////////////// but using x repeaters for x "single record" DataSoruces feels wrong. so i am just wondering is this approach ok?
Hanzaplast
Posts
-
best way of showing single record -
best way of showing single recordhi what is best practice for showing single record from DataSource controls (SqlDataSource, AccessDataSource, ...) this is quite common situation; lets say i need to show simple data from database based on id that is passed via querystring using repeater for only one record feels wrong?
<%#Eval("Name") %> <%#Eval("HTML") %>
<%=DetailHTML() %>
<SelectParameters> </SelectParameters>
-
UpdatePanel inside TemplateFieldhi can i update/insert record directly from markup if i use UpdatePanel inside asp.net GridControls (GridView, DetailsView, FormView...) using SqlDataSource this is what i am trying to do
<%#Eval("html") %>
i can bind "html" field to "tb" TextBox, but executing update or insert command of "gv" i cant update/insert "html" field as long as it is inside UpdatePanel. i can dynamicly find control ("tb" TextBox) using RowUpdating event and set value that way, but i am just wondering if this can be done with no extra code?
-
WebControl - call method from markupcan i call method (not from code behind) to set attribute of server control? in fact i need DataBind - like markup without DataBinding just like
<%#Eval("something")%>
i need something like this
public string Hello()
{
return "hello";
} -
is object part of CollectionBasehi guys can i get Collection from object if it is part of it? code should look something like this
public class SomeCollection : CollectionBase
{
public void Add(SomeClass sc)
{
this.List.Add(sc);
}
}class SomeClass
{
public bool AmIPartOfCollection
{
get
{
//return false or true
}
}public SomeCollection MyCollection
{
get
{
//if this object is part of SomeCollection return his SomeCollection
}
}
}void Main()
{
SomeClass temp = new SomeClass();
//temp.AmIPartOfCollection - want to get false
//temp.MyCollection - want to get nullSomeCollection sc = new SomeCollection(); sc.Add(temp); //temp.AmIPartOfCollection - want to get true //temp.MyCollection - want to get reference to "sc" object
}
-
WCF service - is CallBackChannel alivehi guys, this seems to be easy, but i just cant find right answer. i have WCF duplex service to host online poker game (silverlight on client). if one client plug of his cable or meteor strikes at his home i need to disconnect him. it is easy to implement method Disconnect, but i cant call it if user is unsuspectedly disconnected... my approach is: 1. enter - open page 2. connect - client calls method Connect wich is OperationContract on server; server have array field of all connected clients - CallbackContract 3. do something - send to server your move (irrelevant logic for this question) 4. check clients - this is what i dont have. i want to remove disconected users from my array field of all connected clients 5. recive info - server says what happend to all clients via CallbackContract OperationContext.Current.Channel.Closed and OperationContext.Current.Channel.Faulted sounds like what i need, but they act strange?
public class Poker : IPokerService
{
HttpContext appContext;HttpContext AppContext { get { if(appContext == null) appContext = HttpContext.Current; return appContext; } } Dictionary<string, IPokerClient> ClientList { get { object temp = AppContext.Application\["ClientList"\]; if (temp == null) { temp = new Dictionary<string, IPokerClient>(); AppContext.Application\["ClientList"\] = temp; } return (Dictionary<string, IPokerClient>)temp; } } public void Connect(string id) { Dictionary<string, IPokerClient> clientList = ClientList; try { IPokerClient client = OperationContext.Current.GetCallbackChannel<IPokerClient>(); if (!clientList.ContainsKey(id)) clientList.Add(id, client); else clientList\[id\] = client; OperationContext.Current.Channel.Faulted += new EventHandler(Channel\_Faulted); OperationContext.Current.Channel.Closed += new EventHandler(Channel\_Closed); } catch { //later } } void Channel\_Closed(object sender, EventArgs e) { }
-
Download image from URLyou can use WebClient to download files from url
string url = "http://csmedia.mris.com/platinum/getmedia?ID=90217207979&LOOT=50045650620";
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile(url, "test.jpg"); -
buttons on asp.net 2010 controlsif i understand, you want to preform update, insert, delete functions from other location rather than inside common asp.net grid controls like ListView, FormView, DetailsView... it can be done easily. you just need to call function you want to preform for target control. this is example how to call Update function for FormView outside of FormView
<asp:FormView runat="server" ID="fv" DefaultMode="Edit" DataKeyNames="id" OnItemUpdating="fv_ItemUpdating">
<EditItemTemplate>
<asp:TextBox runat="server" ID="tb" Text='<%#Bind("name") %>' />
<asp:Button runat="server" ID="btn" Text="Edit Inside" CommandName="Update" />
</EditItemTemplate>
</asp:FormView><asp:Button runat="server" ID="btn" Text="Edit Outside" OnClick="EditOutside" />
public System.Data.DataTable SomeData() { System.Data.DataTable temp = new System.Data.DataTable(); temp.Columns.Add("id"); temp.Columns.Add("name"); System.Data.DataRow dr = temp.NewRow(); dr\["id"\] = 1; dr\["name"\] = "somebody"; temp.Rows.Add(dr); dr = temp.NewRow(); dr\["id"\] = 2; dr\["name"\] = "someone"; temp.Rows.Add(dr); return temp; } protected void Page\_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { fv.DataSource = SomeData(); fv.DataBind(); } } public void fv\_ItemUpdating(object sender, FormViewUpdateEventArgs e) { string txtValue = (fv.FindControl("tb") as TextBox).Text; } public void EditOutside(object sender, EventArgs e) { fv.UpdateItem(false); }
-
Multiplayer Pokerhi, i am working on multiplayer online poker. since this is the first time i am doing this kind of thing, i am not sure that i have a good approach. can u tell me your opinion and way this is usually done? i have a asp.net web service on server wich holds information, data and state of games. on client i have Silverlight poker wich is connecting on server every 2 seconds to get current situation via "GameSituation" object. i am afraid of those "2 seconds". if there will be 20 000 players online, is this 2 seconds from each player too much to handle? is this right approach in programming multiplayer games or it can be done like: server waits for client, client contact server, server send info ("GameSituation" object in my case) to all clients in game? is client "hearth loop" good or evil?
-
Clear session after redirecthi guys. i want to store value in session to keep it between postbacks. after page is changed i don't need value anymore. is there a way to kill session on current page i am, before redirect (changing url)? i dont want to use ViewState.
void Page_Load()
{
if(!Page.IsPostBack)
{
Session["something"] = true
}
}
void Page_LoadComplete()
{
//i need this value between postbacks, but dont want to init it every time
bool something = Session["something"] as bool;
}
/*
i would like to have something like this
void Page_IsChangedOrRedirected()
{
Session["something"] = null;
}
*/ -
SqlDataSource - Modify table without primary keyhi guys, thanks for advice and info, but i found a way how to do this. so if anyone have same problem try this solution:
<asp:SqlDataSource ID="sds" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="
select
DoctorID,
PatientID,
DoctorID as DocOldID,
PatientID as PatientOldID
from
DoctorPatient"
UpdateCommand="
update DoctorPatient set
DoctorID=@DoctorID,
PatientID=@PatientID
where
DoctorID=@DocOldID and
PatientID=@PatientOldID">
</asp:SqlDataSource>
<asp:DetailsView runat="server" ID="dv"
DataKeyNames="DocOldID,PatientOldID"
DataSourceID="sds" AllowPaging="true"
AutoGenerateRows="false"
AutoGenerateEditButton="true">
<Fields>
<asp:BoundField DataField="DoctorID" />
<asp:BoundField DataField="PatientID" />
</Fields>
</asp:DetailsView> -
GridView OnClick and OndblCick Attributes in RowDataBoundhi. you can solve problem using asp.net ajax - WebMethods. use this code:
void myGv_RowDataBound(object sender, GridViewRowEventArgs e)
{
string value = e.Row.Cells[0].Text;e.Row.Attributes\["onclick"\] = "PageMethods.InitSession('"+value+"')"; e.Row.Attributes\["ondblclick"\] = "window.location='something.aspx'";
}
[System.Web.Services.WebMethod()]
public static void InitSession(string value)
{
Page page = (System.Web.HttpContext.Current.CurrentHandler as Page);
page.Session["Test"] = value;
}and add this markup on your aspx
<asp:ScriptManager runat="server" ID="sm" EnablePageMethods="true" />
-
SqlDataSource - Modify table without primary keyhi guys, i have simple table without primary key that stores two foregin keys. table contains data about which doctor has which patient.
DoctorID
PatientID
1
1
1
3
1
4
2
1
2
15
what i am trying to accomplish is this:
<asp:SqlDataSource ID="sds" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="select * from DoctorPatient"
UpdateCommand="update DoctorPatient set DoctorID=@DoctorID,PatientID=@PatientID where DoctorID=@DoctorID and PatientID=@PatientID">
</asp:SqlDataSource><asp:DetailsView runat="server" ID="dv"
DataSourceID="sds" AllowPaging="true"
AutoGenerateEditButton="true">
</asp:DetailsView>but editing items wont work... can i set SqlDataSource - DetailsView to modify this table without adding primary ID column?
-
DetailsView FormView - SelectedValue bughi guys. i have strange bug or problem with this two controls. i will simplify my code as much as i can. i have this markup:
<asp:FormView ID="fv" runat="server" DataSourceID="sds" DataKeyNames="id">
</asp:FormView><asp:DetailsView ID="dv" runat="server" DataSourceID="sds" DataKeyNames="id">
</asp:DetailsView><asp:SqlDataSource ID="sds" runat="server" ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
ProviderName="System.Data.OleDb" SelectCommand="SELECT * FROM [tablica]" >
</asp:SqlDataSource>and lets say i need on first PageLoad get SelectedValue from eather of these:
protected void Page_Load(object sender, EventArgs e)
{
object fvValue = fv.SelectedValue;
object dvValue = dv.SelectedValue;
}so here is strange situation (looks like evil bug!). fvValue and dvValue have null value, but debuging code using Visual Studio with brakepoints; when i collapse fv or dv and navigate to SelectedValue property it changes from null to "something"? anyone encounter this situation?
-
urlrewrite - catch all paths on iishi guys. i am working on url rewrite module that works fine on Visual Studio asp.net development server, but not on local IIS. i will minimize my code. here is rewriter class:
public class UrlRewrite : IHttpModule
{
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
//context.AuthorizeRequest += new EventHandler(context_BeginRequest);
}void context\_BeginRequest(object sender, EventArgs e) { HttpApplication ha = sender as HttpApplication; //here i want to do some coding
/*
when running on VS development server i can access all paths of all elements on page,
such as "link" path "App_Themes/LayOut.css" or "img" path "Slike/someimage.jpg" and of course main url
of page "one/two/three" to rewrite it to "Default.aspx?arg1=one&arg2=two&arg3=three"
*//*
when i run page on local IIS i can access only main url (context_BeginRequest fires only one time)
so i can rewirte only main url, but i can't rewrite my css, javascript, images and other
stuffs paths...
*/
}
}so question is: how can i access (request) at context_BeginRequest all elements in IIS like i can in VS development server?
-
dynamic event - pass valuethx. very interesting solution....
-
dynamic event - pass valuehi guys. i have loop which needs to attach event on some elements. event must fire function and pass value from within loop. so here is problem... when loop is over all events fire same argument that is passed by ref not value at that time. <a href="#">link 1</a> <a href="#">link 2</a> <a href="#">link 3</a> <script type="text/javascript"> var anchorNiz = document.getElementsByTagName("a"); for(var i=0;i<anchorNiz.length;i++){ var anchor = anchorNiz[i]; anchor.attachEvent("onmouseover",function(){alert(i)}); //this line does same thing, different value //anchor.attachEvent("onmouseover",function(){alert(anchor)}); } //the idea is to set links to fire ordinal number, but all are fireing '3' </script>
-
ado.net - DataRelation Vs InnerJoini will try to simplify as much as i can what i wrote ahead. let's say i need WebControl that can manipulate data from database. WebControl should have 3 fields (columns). when editing or inserting data via this control, first field is plain text (TextBox), other two must be falling menus (DropDownList). in database i have 3 tables first table have this structure: ------------------------------------------ id | TextField | Foregin1_id | Foregin2_id ------------------------------------------ second and third have this structure: --------- id | name --------- i need to join first table with other two, then bind it to WebControl. so this is my work: 1. i created custom control (class) "MyGird" inherited from the System.Web.UI.WebControls.DataGrid. 2. i created sql query
select
TextField, t2.name, t3.name
from (
table1 t1 inner join table2 t2
on t2.id=t1.Foregin1_id
)
inner join table3 t3
on t3.id=t1.Foregin2_id3. i created some code in "MyGrid" that examines sql query, creates DataSet and fill it with all 3 tables, and finaly calls DataBind() function from it's base class System.Web.UI.WebControls.DataGrid. After bind i have "custom datagird" MyGrid. i can edit MyGrid and manipulate (insert, delete, update) data from first table of database in many ways, depending on "some code i created". so the "problem" is that this "some code i created" is not very "nice". some parts of code is hard to read. globaly this approach doesn't feels right. so question is; can i use DataRelation for joining data from more tables instead of using sql join? DataRelation seems to me like thing i have been mising for creating "MyGrid" in right way....
-
ado.net - DataRelation Vs InnerJoinhi guys i have developed for now several "middle-difficult" web applications. in short lines, they are all composed of custom controls inerhit from DataGrid or DetailsView, using sql queries to populate them with data. in some case their structure could be quite complex. my approach was this: lets say we have somewhat complex query:
select
dip.id,
satnica_obilazak,
gg.naziv,
t.naziv,
klijenti,
iznos as dodatno,
(
select top 1 cijena_sata_rada_obilazak
from klijenti_cijene
where datum<=dip.datum and klijent_id=@klijent_id
order by datum DESC, id
) as cijena_sata_rada,
klijent_idfrom (((
dnevni_izvjestaj_popis dipinner join dnevni\_izvjestaj\_trgovine dit on dit.izvjestaj\_id=dip.id ) left join dnevni\_izvjestaj\_troskovi ditr on ditr.izvjestaj\_id=dip.id) inner join trgovine t on t.id = dit.trgovina\_id )
inner join grupacije_gradovi gg
on gg.id=dip.gradwhere
ditr.klijenti like ('%,'+@klijent_id+',%')
and tip_troska<>1
and tip_troska<>4
and tip_troska<>6this is copy-paste from my project... i made "SqlAnalize" class which is accepting string "sql" as argument. in global, it goes character by character and populate ArrayList of table names from sql string compering to joins (inner join, left join, outer join...). after that i use DataAdapter to populate DataSet with all (or some) tables from sql query. when this is done, algorithm can put DropDownList, CheckBoxList (or whatever i need) in DataGrid. so here i have ClassLibrary with several controls which works this way... recently i had to develop some simmilar class like above, but for Xml source. this is where i met "problem". using xml, DataAdapter fills DataSet very "nice"... "nice" would be best word.... and here i met DataRelation class. i started to study some "DataRelation" tutorials, and find content interesting... so my question is simple: my approach in developing "smart" DataGrid(edit, delete, javascript confirm, dropdown list, uploads, wysiwyg, that kind of stuff inside) is using only sql queries. analize somewhat complex query, pass few values via some property, and finaly bind it. am i doing this wrong way? this DataRelation seems quite interesting. should i change approach? anyone who was working on similiar projects, how did you designed DataSets, DataTable, queries and relation between em? thanks in advan
-
MultLanguage SEOhi guys. i am currently working on the site that supports 4 languages. idea was to create the cookie that contains language value. on the basis of the cookie, server side would withdrawn certain data from database. In this way i would have only one page for all languages(for example "news.aspx") so, my question is: is this way bad for SEO optimization. since there is only one page for all langugaes, crawler will not be able to pass through all languages, only to default. is this way better : news_en.aspx news_hr.aspx news_de.aspx or this: news.aspx?lang=en news.aspx?lang=hr news.aspx?lang=de or is maybe there another way?