Solved

Unable to retrieve div innerHTML value using server side code

Posted on 2006-11-27
3
2,714 Views
Last Modified: 2008-01-09
Dear all,
            I am using C# web form. I am storing some value from data base to my div tag on page load. I update div value using java script . Finally I want to validate the update value in the server side. I am unable to get updated value in the server side. Can anyone help me to solve the problem.

CODE

<DIV id="sc_lbEmpCurCount" style="DISPLAY: inline; WIDTH: 70px; HEIGHT: 15px" runat="server"
            ms_positioning="FlowLayout"></DIV>

Page load server side code
sc_lbEmpCurCount.InnerHtml = iShowCount.ToString();  

using javasript i Update the value

Server Side code
iCurrCount = Convert.ToInt32(sc_lbEmpCurCount.InnerHtml); // I am getting intial value but I want update value




0
Comment
Question by:cosKarthik
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
jay_gadhavi earned 125 total points
ID: 18025644
Try this

I give u an example to solve the problem : it's work perfectly

Html and Javascript



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DivProblem.aspx.vb" Inherits="DivProblem" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript">
function callme()
{
alert(document.getElementById("sc_lbEmpCurCount").innerHTML);
document.getElementById("sc_lbEmpCurCount").innerHTML=""
document.getElementById("sc_lbEmpCurCount").innerHTML="hello from inner html";
document.getElementById("text1").value=document.getElementById("sc_lbEmpCurCount").innerHTML
alert(document.getElementById("sc_lbEmpCurCount").innerHTML);
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
   
    <button id="butt1" name="butt1" value="click Here" runat=server onclick="javascript:callme();" ></button>
   
    <DIV id="sc_lbEmpCurCount" style="DISPLAY: inline; WIDTH: 70px; HEIGHT: 15px" runat="server"  ms_positioning="FlowLayout">
    jayendra
    </DIV>
    <input type=text value="jay" name="hello" id="text1" runat="server"  />
        </form>
</body>
</html>



Server side code :


Partial Class DivProblem
    Inherits System.Web.UI.Page
    Public ishowcount = 29
    Public iCurrCount = 0

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            sc_lbEmpCurCount.InnerHtml = ishowcount.ToString()
            text1.Value = sc_lbEmpCurCount.InnerHtml
        End If

    End Sub
    Public Sub shouwcount()
        iCurrCount = Convert.ToInt32(sc_lbEmpCurCount.InnerHtml) ' // I am getting intial value but I want update value
    End Sub

    Protected Sub butt1_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) handles butt1.ServerClick
        text1.Value = sc_lbEmpCurCount.InnerHtml
    End Sub
End Class

Regards,
jay

0
 
LVL 3

Expert Comment

by:jay_gadhavi
ID: 18025678
If u want the innerhtml value then dont call the butt1_serverclick method (with deleteling the handles or whole method)
0
 

Author Comment

by:cosKarthik
ID: 18026025
I have used hidden control instead of text box
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question