RSS

Dynamic change Image from Database after Page Refresh

25 May

Dynamic change and load Image from Database after Page Refresh with Dropdownlist

Javascript Function

<script language=”JavaScript” type=”text/javascript”>

function showText() {

var ddlReport = document.getElementById(“DropDownList1”);

var Text = ddlReport.options[ddlReport.selectedIndex].text;

var theImages = new Array()

for (var iter = 0; iter < ddlReport.options.length; iter++) {

theImages[iter] = ddlReport.options[iter].value;

} // end for loop

//  alert(theImages)

var j = 0

var p = theImages.length;

var whichImage = Math.round(Math.random() * (p – 1));

for (m = whichImage; m <= whichImage; m++) {

//               alert(theImages[whichImage])

document.write(theImages[whichImage]);

}

}

</script>

Call Javascrit Function from Body Tag

<script language=”javascript” type=”text/javascript”>showText();</script>

<form id=”frm” runat=”server”>

<div style=”visibility:hidden”>

<uc:TestimonialDDL ID=”CTR_TestimonialDDL” runat=”server”  />

</div>

</form>

Server Side Call Funtion at Page Load

Page.ClientScript.RegisterStartupScript(Me.GetType(), “Script”, “showText();”,

User Control

TestimonialDDL.ascx

<%@ Control Language=”VB” AutoEventWireup=”false” CodeFile=”TestimonialDDL.ascx.vb”

Inherits=”Controls_TestimonialDDL” %>

<select id=”DropDownList1″ name=”DropDownList1″>

<%= GetOption()%>

</select>

TestimonialDDL.vb

Public Function GetOption() As String

Return DocumentServices.GetDropDownOption(PassID Here)

End Function

The Problem with Dropdown the image not place accurately on page because drobdown also gain space so disturb the Page. The HiddenField is Comfortable not disturb page

Dynamic load Image after Page Refresh with HiddenField from Database

Javascript Function

<script language=”JavaScript” type=”text/javascript”>

function showText() {

//            var listString = document.getElementById(‘HiddenField1’).value;

var listString = document.getElementById(‘<%= HiddenField1.ClientID %>’).value

var listArray = listString.split(‘|’);

for (var i = 0; i < listArray.length; i++) {

listArray[i];

}

var j = 0

var p = listArray.length;

var whichImage = Math.round(Math.random() * (p – 1));

for (m = whichImage; m <= whichImage; m++) {

document.write(listArray[whichImage]);

}

}

</script>

Body

<div class=”testimonails”>

<script language=”javascript” type=”text/javascript”>showText();</script>

<form id=”frm” runat=”server”>

<asp:HiddenField ID=”HiddenField1″ runat=”server” />

</form>

</div>

File Codebehid Code

Public Function GetOption() As String

Return DocumentServices.GetDropDownOption(Page, “/Global.aspx”, “/testimonails.aspx”)

End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

HiddenField1.Value = GetOption()

Page.ClientScript.RegisterStartupScript(Me.GetType(), “Script”, “showText();”, True)

End Sub

Write this code to make Classes and Split the source content

Public Function GetOption() As String

Return DocumentServices.GetDropDownOption(PassID Here)

End Function

Public Shared Function GetRelatedDocuments(ByVal Documentid As Int32) As DataTable

Dim sqlObj As New SQLManager

Dim hParams As New Hashtable

hParams.Add(“@sectionID”, Documentid

Return sqlObj.getDataTableSP(“get_DocumentsContent”, hParams)

End Function

Public Shared Function GetDropDownOption(ByVal Documentid As Int32) As String

Dim strMainMenu As New StringBuilder

Dim docInfo As DataTable = DocumentDAL.GetRelatedDocuments(Documentid)

If Not docInfo Is Nothing Then

strMainMenu.Append(DropDownOption(docInfo))

End If

Return strMainMenu.ToString()

End Function

Private Shared Function DropDownOption(ByVal docInfo As DataTable) As String

Dim strTemp As New StringBuilder()

If docInfo.Rows.Count > 0 Then

For dtRowcount As Int32 = 0 To docInfo.Rows.Count – 1

If dtRowcount = docInfo.Rows.Count – 1 Then

strTemp.Append(RemoveParagraphTagOp(docInfo.Rows(dtRowcount)(“Content”)))

Else

strTemp.Append(RemoveParagraphTagOp(docInfo.Rows(dtRowcount)(“Content”)))

End If

Next

End If

Return strTemp.ToString()

End Function

Public Shared Function RemoveParagraphTagOp(ByVal strContent As String) As String

Dim str As String = “”

Dim link As String = “”

Dim ListOptions As New StringBuilder()

Dim strHref As String = “”

str = strContent

str = RemoveCommentContent(strContent)

If Not str = Nothing Then

Dim tmpStr As String = “”

Dim startIndex As Integer = 0

Dim endIndex As Integer = 0

str = Replace(Replace(str, “</ a>”, “</a>”), “< /a>”, “</a>”)

str = Replace(Replace(str, “</ A>”, “</A>”), “< /A>”, “</A>”)

str = Replace(Replace(str, “</ img>”, “</img>”), “< /img>”, “</img>”)

str = Replace(Replace(str, “</ img>”, “</img>”), “< /img>”, “</img>”)

str = Replace(Replace(str, “</ br>”, “”), “< /br>”, “”)

str = Replace(Replace(str, “</ br>”, “”), “”, “”)

str = Replace(Replace(str, “</br>”, “”), “<br>”, “”)

tmpStr = str.ToLower

While tmpStr.Contains(“<a”)

startIndex = tmpStr.IndexOf(“<a”)

endIndex = ((tmpStr.IndexOf(“</a>”) + 4) – tmpStr.IndexOf(“<a”))

link = str.Substring(startIndex, endIndex)

str = str.Remove(startIndex, endIndex)

tmpStr = tmpStr.Remove(startIndex, endIndex)

strHref = link

strHref = strHref.Remove(strHref.IndexOf(“>”), strHref.Length – strHref.IndexOf(“>”))

strHref = strHref.Remove(0, strHref.LastIndexOf(“href=”) + 5)

If (strHref.Substring(0, 1) = Chr(34)) Then

strHref = strHref.Remove(0, 1)

End If

If (strHref.Substring(strHref.Length – 1, 1) = Chr(34)) Then

strHref = strHref.Remove(strHref.Length – 1, 1)

End If

‘ListOptions.Append(“<option value='” + link + “‘>” & strHref & “</option>”)

ListOptions.Append(link & “|”)

End While

End If

Return ListOptions.ToString()

End Function

Advertisements
 
Leave a comment

Posted by on May 25, 2011 in Vb.Net

 

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: