Pages

Tuesday, 31 January 2012

Changing the ImageUrl property dynamicaly in ASP.NET

The Image server control enables you to work with the images that appears on your Web Page
from the server side code .It's a simple server control,but it can giv you the power to determine
how your images are displayed on the browser screen.A typical image control is constructed in the following manner.
<asp:Image ID="Image1" Runat="server" ImageUrl="~/MyImage1.gif" />
The following example shows how to change the ImageUrl property of the image control dynamicaly.
VB
<script runat="server">
   Protected Sub Button1_Click(ByVal sender As Object ,ByVal e As System.EventArgs)
                Image1.ImageUrl="~/MyImage2.gif"
   End Sub
</script>
C#
protected void Button1_Click(object sender , EventArgs e)
{
        Image1.ImageUrl = "~/MyImage2.gif ";
}
            

Adding Items to ListBox Control in ASP.NET

To add items to the collection,the following synatax can be usefull
        ListBox1.Items.Add(TextBox1.Text);
You can also add instances of the ListItem object to get different values for the item name and value
VB
    ListBox1.Items.Add(New ListItem("Olivine","MG2SI04"));
C#
    ListBox1.Items.Add(New ListItem("Olivine","MG2SI04"));
The example adds a new instance of the ListItem object,adding not only the textual name of the item,but the
value of the item.It produces the following results in the browser:
          <option value="MG2SI04">Olivine</option>

ASP.NET(C#) code to change the unique identifier of the anonymous User

//Code that change the Unique identification of the anonymous user is like the code below..try this..

public void AnonymousIdentification_OnCreate(object sender, AnonymousIdentificationEventArgs e)
    {
        e.AnonymousID = "Bubbles" + DateTime.Now();
    }