in asp.net page_load without using runat = "server" I need to do the following two things ... ...">

How to set the value of <input type = "hidden"> in asp.net page_load without using runat = "server"

I need to do the following two things ...

  • I want to set the value in asp.net page_load. the problem is that I do not want to use runat = "server". I tried this following but this does not work:

HtmlInputHidden hiddenControl = (HtmlInputHidden) FindControl ("a");

is there any way to access asp.net page_load without using runat = "server" ??

  1. I can do this if I use, but in this case I cannot access it in the javascript function of the main page. I tried this, but it does not work ...
    • var hdnField = document.getElementById ('<% = hdnIdentity.ClientId%>');
    • var hdnField = document.getElementById ("hdnIdentity"). getAttribute ("value");
    • var hdnField = document.getElementById ("hdnIdentity"). Value

what i need ... I want to access the hidden value of the content of the page in javascript on the main page. is there any way ??? thnx pre-reviews Haroon haroon426@yahoo.com

+3
source share
6 answers

I sometimes do the following, especially when I want to control my identifiers (especially when using jquery).

<asp:literal id="literal1" runat="server"><input type="hidden" id="someid" value="{0}"/></asp:literal>

Then in the code you can set the value with the following:

literal1.Text = string.Format(literal1.Text, "somevalue");

It cannot do without using runat = "server", but you did not indicate why you do not want to do this. In addition, you need to get the value using request.form

Update

.net 4.0 . . :

http://weblogs.asp.net/asptest/archive/2009/01/06/asp-net-4-0-clientid-overview.aspx

+6

IIRC, HttpRequest.Forms, - .

+2

POST, Request.Forms Request.QueryString, GET.

+1

ad 1) aspx <input type="hidden" value="<%=GetHiddenValue%>" />.

public class MyPage : Page {
  protected GetHiddenValue { get { /*...*/ } }
+1

javascript, , , ClientID . runat = server, , .aspx, , HTML. . , Request [tagName]

+1

ad 2) html- id <input type="hidden" id="myHiddenField" />. javascript document.getElementById('myHiddenField').

+1

Source: https://habr.com/ru/post/1723140/


All Articles