Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Wednesday, March 28, 2012

Accessing Controls embedded in panel within hoverMenuExtender

I have a Panel with labels inside. I need to add more labls dynamically on run time depending what is returned from a database. This panel is referenced by the hoverMenuExtender. The problem is, is that I cant access any of the panels ID's in the code behind. You can see from the code below in lines 23-42. I need to add more labels there dynmically depending on what is returned from the database on Page_Load.
  
1 <asp:DataList ID="DataList1" runat="server" AlternatingItemStyle-BackColor="ivory"2 CellPadding="5" RepeatColumns="5" Width="92%">3 <HeaderTemplate>4<!-- <table id="RepeaterTable1" border="0">5 <tr>6 <th>ID</th>-->7 <b>8 <asp:Label ID="lblTime2" runat="server"></asp:Label></b>9<!--<th>IP</th>-->10 </tr>11 </HeaderTemplate>12 <ItemTemplate>13<!-- <tr>14 <td><%#Container.DataItem("ID")%></td>-->15 <asp:Panel runat="server" ID="panelMain">16 <asp:Image ID="Image1" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("imgName")%>'17 Width="21px" />18    19<%#Container.DataItem("ServerName")%>20 </asp:Panel>2122 <asp:Panel ID="hovPanel" runat="server" BackColor="black" Width="300px" ForeColor="white">23 <asp:Image ID="hovImage" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconPing")%>'24 Width="21px" />  <asp:Label runat="server" ID="hovDisk" text='<%#Container.DataItem("hovPing")%>' />25 <br />26 <asp:Image ID="Image3" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconPhy")%>'27 Width="21px" />  <asp:Label runat="server" ID="Label2" text='<%#Container.DataItem("hovPhy")%>' />   <asp:Label runat="server" ID="Label3" text='<%#Container.DataItem("hovPerPhy")%>' />28 <br />29 <asp:Image ID="Image4" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconVirt")%>'30 Width="21px" />  <asp:Label runat="server" ID="Label4" text='<%#Container.DataItem("hovVirt")%>' />   <asp:Label runat="server" ID="Label5" text='<%#Container.DataItem("hovPerVirt")%>' />31 <br />32 <asp:Image ID="Image2" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconDiskOne")%>'33 Width="21px" />  <asp:Label runat="server" ID="Label1" text='<%#Container.DataItem("hovDiskOne")%>' />   <asp:Label runat="server" ID="Label10" text='<%#Container.DataItem("hovPerOne")%>' />34 <br />35 <asp:Image ID="Image5" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconDiskTwo")%>'36 Width="21px" />  <asp:Label runat="server" ID="Label6" text='<%#Container.DataItem("hovDiskTwo")%>' />   <asp:Label runat="server" ID="Label9" text='<%#Container.DataItem("hovPerTwo")%>' />37 <br />38 <asp:Image ID="Image6" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconDiskThree")%>'39 Width="21px" />  <asp:Label runat="server" ID="Label7" text='<%#Container.DataItem("hovDiskThree")%>' />   <asp:Label runat="server" ID="Label8" text='<%#Container.DataItem("hovPerThree")%>' />40 <br />41 <asp:Image ID="Image7" runat="server" Height="21px" ImageUrl='<%#Container.DataItem("hovIconCPU")%>'42 Width="21px" />  <asp:Label runat="server" ID="Label11" text='<%#Container.DataItem("hovCPU")%>' />   <asp:Label runat="server" ID="Label12" text='<%#Container.DataItem("CPUPer")%>' />4344 </asp:Panel>45 <ajaxToolkit:RoundedCornersExtender ID="rnd" runat="server" TargetControlID="hovPanel" Radius="6" />46 <ajaxToolkit:HoverMenuExtender ID="HoverMenuExtender1" runat="server" PopupControlID="hovPanel" TargetControlID="PanelMain" OffsetX="0" OffsetY="0" PopDelay="50" PopupPosition="bottom">47 </ajaxToolkit:HoverMenuExtender>4849 </ItemTemplate>50 <FooterTemplate>51<!--</table>-->52 </FooterTemplate>53 </asp:DataList>

And you say that you *can* reference the panel Id's when you're not using an UpdatePanel?I've frequently had trouble finding controls when they're part of a collection inside another control, even previous to ajax extensions work.

Typically, I've resorted to iterating over the items collection of the datalist to do it, using the syntax DataList1.Items[i].FindControl("controlId") to hook into it as you iterate.


But I ned to "Add" a control (label) to the datalist item template. how do I do this? I can do a DataList1.Items[i].FindControl("controlId"), but how do I add items to the list? Thanks for the reply by the way. I am on a short time table here. :)

Right, well, my point is that you're trying (I thought) to add a new label to that one panel that's got a bunch of labels on it, right? to do that, you need to first get an instance of the Panel (iterating over the control tree and returning the one you want). Then, you'd add it to that panel's control collection just like you normally would add a dynamic control, e.g. myPanel.Controls.Add(someLabelYouJustCreated);

Can I ask, though, what's the lifespan of these labels? Because, if they only last as long as the page is in view to the user, it might be easier to add them as clientside objects rather than serverside ones. Just soemthing to think about.


Thanks for the fast reply. You are right that I am trying to add labels dynamically to the panel inside the datalist. I get the intellisense for the datalist, but in the code behind it did not register (intellisense see) the panel. I cant do it on client side because the labels I am filling is coming from a database. So when I type hovPanel.xxx.xxx it says that hovpanel is not declared. thats where my problem is coming from.

I guess I need to get an instance of the panel, but I cant. I tried creating a new one in the code behind with the same name and it runs fine, but nothing gets added to the panel

i.e.

Dim hovpanel as panel = new panel (Although there is already a panel in the .aspx with the ID of "hovpanel"


Right, that's my whole point about the FindControl method. I don't do VB very well, so let me speak in abstract terms. you should say Dim hovPanel as Panel = findPanel("hovPanel") (or some such). findPanel() is a method you define which loops through the items of datalist1 to look for one with the id matching the above; I previously described this.

http://samples.gotdotnet.com/quickstart/aspplus/doc/webdatalist.aspx

That's a good example as well.


Ahh, I see where you are going. Thanks. I am going to give it a try.

Thanks Paul. I did this and it worked...

Dim lbl1As Label =New Label lbl1.Text ="PRINT ME"Dim yAs Integer For y = 0To DataList1.Items.Count - 1Dim hovpanelAs Panel = DataList1.Items(y).FindControl("hovpanel") hovpanel.Controls.Add(lbl1)Next
Now within the "FOR" loop and can run tests to see how many labels are there and how many to add and what not. Thanks a Million !!! :)


Glad I could help.

Saturday, March 24, 2012

Accents with ASP.NET AJAX

Hi Everybody, I'm starting study ASP.Net AJAX, and i have a problem!

I create an application with DataBase and GridView, and accents in mine language is not functioning! (portuguese-Brazil) !!!!

What do i must do?

Sorry, I'm Brasilian, My english isn't good!!!

hello.

well, you should take a look at the globalization element:

http://msdn2.microsoft.com/en-us/library/hy4kkhe0.aspx


I tried this, but it does not function exactly, places invalid characters!!!

Tanks

(Portugues)

Eu ja tentei isso, mais ainda n?o funciona! Ele coloca caracteres invalidos!!!

Obrigado


Hi,

In the gridview, there's a property calledHtmlEncode which allows me todisplay the text as I whished, even if the thare accents (I'm doing it with french), and also I have declared in my globalization enviroment the french (<globalizationrequestEncoding="utf-8"responseEncoding="utf-8"culture="fr-FR"/>)... I suppose that should be enough...

I once had a similar issue during display of some text from the database and I was able to solved with the statement:

Server.HtmlDecode(MyString)

Abort SQL query when aborting callback

Hi,

I have got a page that depends on database queries that may take a couple of minutes to complete.
The page shows an UpdateProgress element and the idea is to add an "abort" button to it.
As far as I remember it should be easy to abort the browser callback.

Ideally I would like to have the database query/command aborted too to prevent a waste of precious resources (SQL Server 2005).

I wonder what will happen to the orphan callback after it has been aborted.
If I am lucky, what happens is the following:

1. When the user aborts the callback, the HttpRequest is destroyed.
2. The keep-alive mechanism allows the web server to detect that the request under process is now orphan.
3. The relevant Page object is then destroyed.
4. Similarly, SQL Server looses contact with the "consumer", that is the Page, and automatically aborts the query.

If this is not the case, is there a way to obtain the same result?

Thanks in advance,

Paolo

Here are some sample codes to abort asynchronous post back through javascript for your reference.

<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
function AbortPostBack() {
if (prm.get_isInAsyncPostBack()) {
prm.abortPostBack();
}
}
</script>

Wish the above can help you.


Thanks. What I am asking is if there is a way of cancelling the SQL query run by the call.

When a call is aborted the Response.IsClientConnected property value will become false. So I think what you need to do is to poll for the Response.IsClientConnected value and abort the query when it returns false (using SqlCommand.Cancel). This also means that you need to execute your query asynchronously.


I am facing similar problem.I try to use "Response.IsClientConnected".ut I found that it always returns "true" ( seems to be a bug).I am using IIS 6.

Is there any other work around for it ?

Thanks,

Vijay

Wednesday, March 21, 2012

A group of PostBackTrigger in my updatepanel

I use a repeater to print out information (hyperlinks) from my database. When you click a hyperlink I want to update a updatepanel.

The problem is that the controlID for each link must be typed in a PostBackTrigger to work perfectly. I can't add PostBackTriggers at run time? Any solutions?

Regards Gustav


Can't you set your updatepanel's mdoe="Always" ?
If I remove my triggers and set UpdateMode="Always" the updatepanel updates without Ajax.

The easiest maybe to handle the hyperlink click event on the server side, and update the desired updatepanel in the click event by the .Update() method.

For handling all hyperlink click event in single event in the server side, and determine which link was clicked: check msdn for handling events in repeater, this is a regular asp.net task not ajax. Search for: "How to: Respond to Button Events in DataList, Repeater, or GridView Items"