0

I know my question is duplicate of here but still facing problem

In my javascript code I have tried different way of assigning text to label are

 function fileuploadvalidation() {
document.getElementById("<%=lableid.ClientID%>").Text = "hello"; 
document.getElementById("<%=lableid.ClientID%>").innerHTML = "hi";
}

and its use to be seen text on my .aspx page also but when I used to fetch that text on my server side it is coming blank.

.html page code

<asp:UpdatePanel ID="UpdatePanel16" runat="server"><ContentTemplate>
<asp:Button ID="btn_browse" runat="server" Text="Upload" OnClick="btn_browse_Click" OnClientClick="return fileuploadvalidation();" />&nbsp;&nbsp;
<asp:Label ID="lableid" runat="server" Text="" Style="font-size: small; font-weight: 400;font-family: Arial, Helvetica, sans-serif"></asp:Label> 
</ContentTemplate></asp:UpdatePanel>

.cs code

protected void btn_browse_Click(object sender, EventArgs e)
{
    string abc = lableid.Text;// This is coming null
}
Community
  • 1
  • 1
Mitesh Jain
  • 555
  • 4
  • 13
  • 40

3 Answers3

2

Use hidden-field to store the value that you set,then access it in code behind

add a hidden field

 <input type="hidden" id ="hiddenfieldid" runat="server" />

.

function fileuploadvalidation() {
    document.getElementById("lableid").value = "hello"; 
    document.getElementById('hiddenfieldid').value= "hello"; 
}

then retrieve it in code behind.

string abc = hiddenfieldid.value;
Sajad Karuthedath
  • 14,987
  • 4
  • 32
  • 49
  • not working,i have tried and even label is also not showing on .aspx – Mitesh Jain Jan 23 '14 at 12:12
  • hey its working, can you make me 1 more favour?? The text showing on .aspx page gets blank as i used to click the button, what should i do for not to make that label text blank – Mitesh Jain Jan 23 '14 at 12:22
  • @MiteshJain just set the value of the hidden field back to the label in code behind,or you may use jquery to set the value using the val function – Sajad Karuthedath Jan 23 '14 at 12:25
0

I think you want to add set the value property of the label

 var lbl = document.getElementById("<%=lableid.ClientID%>")
 lbl.value = "hello"; 
owenrumney
  • 1,520
  • 3
  • 18
  • 37
0

try to use this

 $('#lableid').val($('#lableid').val().replace($('#lableid').val(), "hello"));
Mahmoude Elghandour
  • 2,921
  • 1
  • 22
  • 27