Solved

Unable to retrieve div innerHTML value using server side code

Posted on 2006-11-27
3
2,701 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now