Solved

Unable to retrieve div innerHTML value using server side code

Posted on 2006-11-27
3
2,730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

726 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