Category Archives: Label

[RESOLVED] Sending Data Between Iframes.

Hi

I've got a situation where there is a page with 3 iframes. The first frame contains a TreeView, the second a GridView which is dependent on the selected node of the Treeview in frame 1 and the third frame contains labels with information also dependent on the TreeView in the first frame.

My problem is, how do I pass information from the first frame to the others? Can I access information about the selected node in JavaScript, pass it to another frame and then do a postback with the info as an argument?


Thanks

Hi

You can see explaination here from

sharing variables between windows and frames

accessing variables from one frame to another

Now, sharing variables between frames is not really any different than sharing them between windows. All you need is a reference to the frame object.

For example, if a window has two frames, the first frame can access a variable in the second frame using the following expression:

Example: first frame accessing second frame's variable

parent . frames [1] .
variable_name

Similarly, the second frame can access variables in the first frame through the following expression:

Example: second frame accessing first frame's variable

parent . frames [0] . 
variable_name

As illustrated in these examples, frames can obtain references to neighboring frames through the parent window's

frames []
property. Don't forget that the first frame in this array is indexed with 0, not 1.


Regards

shabir

Hi

Thanks, I have no problem passing JavaScript variables between frames, the problem is how do I pass info from the server control to JavaScript? I've been experimenting with the IscriptControl interface, I'd like to bind a function to the window's onload event so after the user clicks on the TreeFrame it does a postback and when the window has finished loading it can pass the selected node onto the other frame with the gridview.

Regards

Hi,

You can consider to pass value between Iframe by using QueryString in Iframe src property.

Like:

<iframe id="frm" src="page.aspx?p1=1">

Or code behind:

Iframe.Attributes["src"] = "page.aspx?p1=" + HttpUtility.UrlEncode(p1);

You can check this link:

http://www.codeproject.com/KB/aspnet/IFrameParams.aspx

Hope this can help you.

Accessing Database from Silverlight

Hi All,

I am working on Silverlight 2 Beta 2. I ma trying to bind the data to a DataGrid from the DB using LINQ. When I search in the net all articles are talking about binding the data using WCF Service only.

Without WCF we cannot bind the Data?

 I want to design a DataGrid like below


___________________________________________________
|               |                |               Number of                               |
|               |                |___________________________________|
|Column1  |Column 2 |SubColumn1|SubColumn2|SubColumn3|
|________|________ |__________|__________|____________|
| 1          |  a          | as            | fg             | gh            |
| 2          |  b          | sd            | fg             | fgh           |
| 3          |  c          | df             | fg             | fgf           |
________________________________________________

Total     | Total of this Col | same | same...

Let me know

Thanks

Anandraj.A.

You have only 2 method to bind grid in the silver light 1). WCF and 2). Web service (asmx).
1. Create Interface for Datagrid(classes, methods)
2. Create User Control as a Label
3. You have to design a datagrid as your wish by the user control or any.
4. Place table-data into the Label-User-Control through WCF

Note: Dropdown also possible by User Control


 Hi Anandraj

it is a little tricky at best to get databinding in silverlight,  take a look at these videos should help. ado.net data services made life a little easier (but not much) seems to be the way to go.but im not sure if it works with beta, any reason you are using beta?

http://www.microsoft.com/uk/msdn/screencasts/screencast/308/adonet-data-services-a-basic-silverlight-client.aspx

Im not sure about doing it with silverlight 2 beta either?, I know the datagrid changed at some point from beta to live (i think anyway) so you may hit a problem with that.

Hi anand,

WCF is the most suitable way to bind the data in Silverlight applications. We can use LINQ TO SQL classes to create the data layer mapped over SQL Server tables. Further by creating Silverlight-enabled-WebService we can access above created LINQ classes to access the data and fetching to Silverlight application.

First create a silverlight application.

Secondly,

Now that you have created the Silverlight 3 Application, we would add a LINQ to SQL file that is *.dbml .

LinqToSQLSilverlight2.gif


Thirdly,

To communicate with LINQ to SQL we need to have a service that client can call at any time.

Add Silverlight enabled WCF Service to the Web Project.

LinqToSQLSilverlight7.gif


In the Service.svc.cs add methods as per your requirement.

I have written two methods such as:


#region [GetAllEmployees]


        [OperationContract]
        List<vw_mst_EmployeeDetail> GetAllEmployees()
        {
            using (EmployeeDBDataContext context = new EmployeeDBDataContext())
            {
                var result = from emp in context.vw_mst_EmployeeDetails
                             select emp;


                return result.ToList();
            }
        }


        #endregion


        #region [GetEmployeesByFirstName]


        [OperationContract]
        List<vw_mst_EmployeeDetail> GetEmployeesByFirstName(string firstName)
        {
            using (EmployeeDBDataContext context = new EmployeeDBDataContext())
            {
                var result = from emp in context.vw_mst_EmployeeDetails
                             where emp.FirstName.StartsWith(firstName)
                             select emp;


                return result.ToList();
            }
        }


        #endregion


Fourthly,

After writing the service build the project and get this service's reference in Silverlight 3 Project as shown in below figure.

LinqToSQLSilverlight10.gif


<div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        #region [GetAllEmployees]</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        [OperationContract]</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        List<vw_mst_EmployeeDetail> GetAllEmployees()</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        {</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            using (EmployeeDBDataContext context = new EmployeeDBDataContext())</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            {</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                var result = from emp in context.vw_mst_EmployeeDetails</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                             select emp;</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                return result.ToList();</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            }</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        }</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        #endregion</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        #region [GetEmployeesByFirstName]</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        [OperationContract]</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        List<vw_mst_EmployeeDetail> GetEmployeesByFirstName(string firstName)</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        {</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            using (EmployeeDBDataContext context = new EmployeeDBDataContext())</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            {</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                var result = from emp in context.vw_mst_EmployeeDetails</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                             where emp.FirstName.StartsWith(firstName)</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                             select emp;</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">                return result.ToList();</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            }</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        }</div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 926px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        #endregion</div>

After you add the service it would create the ServiceReferences.ClientConfig file.

Now it's time to design our Silverlight UI in Blend, I have gone for a simple approach, where simple buttons and textbox would help us getting the result which would be displayed in DataGrid.


LinqToSQLSilverlight11.gif


XAML for your reference is as follows - 


<UserControl

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 

    mc:Ignorable="d" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="Mazeweb.Silverlight.MainPage"

    d:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot">

     <Grid.Background>

     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">

     <GradientStop Color="#FFF2F2F8" Offset="0.948"/>

     <GradientStop Color="#FF5B99F2" Offset="0.665"/>

     </LinearGradientBrush>

     </Grid.Background>

     <Grid.RowDefinitions>

     <RowDefinition Height="0.106*"/>

     <RowDefinition Height="0.056*"/>

     <RowDefinition Height="0.838*"/>

     </Grid.RowDefinitions>

        <TextBlock HorizontalAlignment="Center" Text="LINQ TO SQL &amp; SILVERLIGHT 3" 

             TextWrapping="Wrap" FontSize="21.333" TextDecorations="Underline" Margin="0,3,0,19" d:LayoutOverrides="Height"/>

        <StackPanel Margin="0" Height="80" VerticalAlignment="Center" Orientation="Horizontal" 

                    HorizontalAlignment="Center" Grid.Row="1">

            <Button x:Name="btnAll" Height="25" Content="Show All" Click="btnAll_Click" VerticalAlignment="Center" Margin="0,0,0,8" Width="109" />

            <Rectangle Height="25" Width="10"/>

            <TextBox x:Name="txtName" Height="25" TextWrapping="Wrap" Width="164" VerticalAlignment="Center"/>

            <Rectangle Height="25" Width="10"/>

            <Button x:Name="btnSubmit" Height="25" Content="Search" Click="btnSubmit_Click" VerticalAlignment="Center" Margin="0,0,0,8" Width="109" />

        </StackPanel>

        <data:DataGrid x:Name="dgResults" Margin="8,10,8,89" Grid.Row="2" IsReadOnly="True" 

                       AutoGenerateColumns="False">

            <data:DataGrid.Columns>

                <data:DataGridTextColumn Binding="{Binding ID}" Header="ID"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding FirstName}" Header="First Name"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding LastName}" Header="Last Name"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding UserCode}" Header="EmailID"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding DesignationName}" Header="Designation"></data:DataGridTextColumn>

                <data:DataGridTextColumn Binding="{Binding BranchName}" Header="Branch"></data:DataGridTextColumn>

            </data:DataGrid.Columns>

        </data:DataGrid>

    </Grid>

</UserControl>

<div>
</div><div>
</div><div>Finally,</div><div>
</div><div>Now we would write client side code to call the service and display the result.

Following code is for Show All Button Click and displaying the result.
</div><div>
</div><div><div>        private void btnSubmit_Click(object sender, RoutedEventArgs e)</div><div>        {</div><div>            ServiceClient clientService = new ServiceClient();</div><div>            clientService.GetEmployeesByFirstNameCompleted += new EventHandler<GetEmployeesByFirstNameCompletedEventArgs>(clientService_GetEmployeesByFirstNameCompleted);</div><div>            clientService.GetEmployeesByFirstNameAsync(txtName.Text);</div><div>        }</div><div>
</div><div>        void clientService_GetEmployeesByFirstNameCompleted(object sender, GetEmployeesByFirstNameCompletedEventArgs e)</div><div>        {</div><div>            dgResults.ItemsSource = e.Result;</div><div>        }</div><div>
</div><div>        private void btnAll_Click(object sender, RoutedEventArgs e)</div><div>        {</div><div>            ServiceClient clientService = new ServiceClient();</div><div>            clientService.GetAllEmployeesCompleted += new EventHandler<GetAllEmployeesCompletedEventArgs>(clientService_GetAllEmployeesCompleted);</div><div>            clientService.GetAllEmployeesAsync();</div><div>        }</div><div>
</div><div>        void clientService_GetAllEmployeesCompleted(object sender, GetAllEmployeesCompletedEventArgs e)</div><div>        {</div><div>            dgResults.ItemsSource = e.Result;</div><div>        }</div><div>
</div><div>
</div><div>Now, Finally you can test your application successfully running.</div>
</div>


Hope this POST helps.


I wrote an article about connecting a datagrid to a silverlight project here. Perhaps it will be useful.

Hi Dear

You have three option

1: Linq to Sql server

2. WCF Service

3. Web Service

[RESOLVED] Eval(Session("session_variable"))

Can I Eval a session variable in WebForms? 

Check out this example:

ASPX

<%@ page language="C#" masterpagefile="~/MasterPages/Default.master" autoeventwireup="true"
	codefile="CallAMethodInline.aspx.cs" inherits="HowTo_CallAMethodInline"
	title="How To: Call A Method Inline" %>

<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="Server">
	<div>
		Static Method: <%= MathHelper.Add(2, 2) %>
	</div>
    <div>
        Protected Method: <%= Add(2, 2) %>
    </div>
    <div>
        Protected Property: <%= Result %>
    </div>
    <div>
        Session Object: <%= Session["Result"] %>
    </div>
</asp:content>



CODE-BEHIND

using System;

public partial class HowTo_CallAMethodInline : System.Web.UI.Page
{
    protected int Result;

    protected void Page_Load(object sender, EventArgs e)
    {
        Result = this.Add(2, 2);
        Session["Result"] = this.Add(2, 2);
    }

    protected int Add(int x, int y)
    {
        return x + y;
    }
}



Okay, that worked, thanks for the great example. BUT, can you not use the same approach to a <asp:TextBox or <asp:Label using Eval or Bind, i.e;

<asp:TextBox id="txt_userId" runat="server" Text='<%# Eval("Session(""USERID"")") %>' 

Thank you!

To the best of my knowledge, you can't do that, unless someone else knows of a way.

[RESOLVED] Create aspx page dynamically

Hi ,


Can anyone tell me as how to create aspx page dynamically.

The controls are defined by user in run time.

Based on that i want to create aspx page.

Else its enough if i am able to generate basic structure of aspx page.(i.e The basic firm which generates when we add new webform in visual studio)

Later i can develop with it.

Thanks,

MR




Hi,

Aspx page is just Page Object,so you can dynamically generate it like

Creating ASPX page dynamically using BLL - ASP.NET Forums

Creating ASPX page dynamically using BLL - ASP.NET Forums


Regards

shabir

Hi ,

Thanks for your replies.

Actually i want the page to be created dynamically on button click and make it available for download using Response.Write method.


How to do it?


Thanks,

MR..

what is the file extension of  page that you will create.
populate stringbulilder with neccessary code including neccessary<html><body>
write this to any file and save to your disk.


What I have understood is that you want to get dynamic Html to a file...

in that case it is easy if you are dealing with fairly simple Html....you can use normal StringBuilder to get the thing done...

but if you want to have ASP.Net server controls html...then you got to use Control.Render() method to get the content and then you have to include that content in the Output html....

So what I suggest is you have to build a custom HtmlUtility class which will handle all the controls and make the mark up....once you have this class in perfect shape...you can get the complete html, then build up a Html file and send it to client for download....

Thanks

Hi Rami,

Thanks for your reply.

It was very usefull.

But in this render method it converts the control as output.

But i want the controls as such without output.

i.e if Label say <asp:Label id="lblSample" runat="server">

I want this to be created.

How to do it?


Thanks ,

MR


Then you got to dynamically create it....like this....

Label lebl = new Label();

lebl.Id = "1";

lebl.Text = "Hello";

Page.Controls.Add(lebl);


And remember all the dynamic controls needs to be creareted on every postback....

Thanks.

[RESOLVED] Removing white space when aspx label is hidden

I have a page with several asp labels with no text.  I use a click event to add text the fields that have related values from a datareader.  In my code I state that if column value of the datareader is null, then make the label visibility false.

for ex:

 if (sdr["college"] == DBNull.Value)

{

     collegeLabel.Visible = false;

}

else

{

     collegeLabel.Text += "College: " + sdr["college"].ToString() + "";

}

 

 

That all works fine, but then when I render the page, white space where the hidden labels are located is shown.

Is it possible to remove the blank white space when labels have null values and are visually hidden?

Thanks 

If you are using html table layout, set TableRow Visible to false instead of label. 

You can hide the table row in codebehind as well.. 

tr1.Visible=false;

<table cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <b>Test Row 1</b>
        </td>
    </tr>
  <tr runat="server" visible="false" id="tr1">
        <td>
            <asp:Label ID="Label1" Text="Test Label" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            <b>Test Row 2</b>
        </td>
    </tr>
</table>

Thanks for your response.

 

Actually I had my labels in a panel, instead of table.

 

Is it possible to remove space of a hidden control within a panel? 

Hi,

Alternaive way I think you can try to use css like display or visibility.

 

For example:

this.Label1.Style.Add("display", "none ");
 this.Panel1.Style.Add("visibility", "hidden");

Or

<div>
                something<span style="display: none">Some text</span>something</div>



 You can have a look at this link:

http://www.htmlforums.com/html-xhtml/t-blank-space-using-span-stylevisibilityhiddendisplaynonesome-textspan-66887.html

http://stackoverflow.com/questions/4597078/javascript-control-style-display-none-and-control-style-display

Hope this can help you.

Thanks for your reply, I'll try this when I get back to my project a little later.