Aspx get value from confirmed HTML - c#

I would like to get value from label with id=lblValue. On page confirm I see confirmed HTML as:
<span class="treeColorOrderBefPrepare">~
<div style='display:inline-block;'>
<img onclick='calculateDate.add(this);' style='cursor:pointer;' class="imageInBox" src="/_assets/images/icons/small/add.png"/>
<img onclick='calculateDate.subtract(this);' style='margin-left:3px;cursor:pointer;' class="imageInBox" src="/_assets/images/icons/small/subtract.png"/>
<label id='lblValue' style='position:relative;top:1px;width: 13px; height: 13px;margin-left:3px;margin-right:3px;'>0</label>
</div>
<img class="imageInBox" src="/_assets/images/icons/small/icon-small-merchandise.png"/>POPER ČRNI MLETI (0,0 KG) (fina. HKJ_TK, predp. Cent.predp: 04.04.2017 - 0,0 KG)</span>
<input type="text" name="DK_m_1_3_120000204_140000240-120003917-120000204-" value="">
All I need is to get value from lblValue. Is there a way to get this value? Values will range from -10 to 0. In the example above, value=0. I am doing this on the server side, not on the client side.

<script type="javascript">
document.getElementById("lblValue").innerHTML
</script>

Add runat="server" attribute like this:
<label id='lblValue' runat="server" style='position:relative;
top:1px;width: 13px; height: 13px; margin-left:3px;margin-right:3px;'>0</label>
and you will be able to use lblValue as a variable.
For more information, what runat attribute is doing, please see this: Why does ASP.NET webforms need the Runat="Server" attribute?

Related

How to get text from a template text field in asp.net?

I have used a login-template for the page in .net application. How can I get the texts from the input text fields of the template and store it in a string variable?
<form id="form1" runat="server" role="form" method="post" class="login-form">
<div class="form-group" runat="server">
<label class="sr-only" for="form-username">Username</label>
<input type="text" name="form-username" placeholder="Username..." class="form-username form-control" id="form_username" runat="server"/>
</div>
<div class="form-group" runat="server">
<label class="sr-only" for="form-password">Password</label>
<input type="password" name="form-password" placeholder="Password..." class="form-password form-control" id="form_password" runat="server"/>
</div>
<button type="submit" class="btn" onclick="btn_login_Click" runat="server">LOGIN</button>
</form>
To get the Text in a TextBox you can simply do this:
private void AnyMethod()
{
string textValue = this.MyTextBox.Text;
}
You can access the raw post data with:
string exampleInput = Request.Form["<inputElementName>"];
If your input element is having the attribute 'runat="server"' you should be able to access it with
string exampleInput = <inputElementName>.Value;
If this does not work, you would need to show us a little bit more of your code/page.
Sample form:
<form id="login" runat="server">
<asp:TextBox ID="tbInput1" runat="server"
Width="75px"
TabIndex="1">
</asp:TextBox>
<asp:Button ID="btSubmit" runat="server" Text="Submit" />
</form>
Access with
tbInput1.Text
I guess ,if runat=server is there then it should directly get value using :
form_username.value.Tostring().
After doing little research on above issue got to know that ,
we can't access the login control properties directly .
if we want to access name then we have to use : User.Identity.Name
try doing this ! it might help you .
For further reference please visit below link :
https://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirecttologinpage.aspx

AJAX Collapsible Panel Extender Code Behind

I am having some problem with AJAX Collapsible Panel Extender. Currently what I am trying to do is when certain panel is extended, then it will perform some sql statement. I have no idea on how to write the code other than just squeeze all of them in the Page Load method. Here is how I set up my collapsible panel extender:
<!-- FIRST COLLAPSIBLE PANEL EXTENDER -->
<asp:Panel ID="pHeader1" runat="server" CssClass="cpHeader">
<!-- First collapsible panel extender header -->
<div class="form-group" style="background-color:#ffb848; height: 30px; vertical-align: middle">
<div class="col-md-3">
<div style="float: left; color: White; padding: 5px 5px 0 0">
Collapsible Panel
</div>
</div>
<div class="col-md-9">
<div style="float: right; color: White; padding: 5px 5px 0 0">
<asp:Label ID="lblHeaderText1" runat="server" />
<asp:Image ID="imgArrows1" Text = "IMAGE" runat="server" />
</div>
</div>
<div style="clear: both"></div>
</div>
</asp:Panel>
<!-- First collapsible panel extender body -->
<asp:Panel ID="pBody1" runat="server" CssClass="cpBody">
<asp:Label ID="lblBodyText1" runat="server" />
Hey there
</asp:Panel>
<asp:CollapsiblePanelExtender ID="cpe1" runat="server" TargetControlID="pBody1" CollapseControlID="pHeader1"
ExpandControlID="pHeader1" Collapsed="true" ImageControlID="imgArrows1"
CollapsedImage="~/Images/downarrow.jpg"
ExpandedImage="~/Images/uparrow.jpg" TextLabelID="lblHeaderText1" CollapsedText="Show"
ExpandedText="Hide" CollapsedSize="0" ExpandedSize="200"
ScrollContents="true">
</asp:CollapsiblePanelExtender>
Any related research link would be appreciated. Thanks in advance.
This is possible.
In gist you are supposed to work with the ajax client-side page life-cycle. Like there is a page load in your server-side aspx page; there is a page load in the client (i.e. the web page rendered in the browser) which happens after all the asp.net client ajax js libraries are all loaded.
In that you are supposed to do something like:
//this would be <%=myExtender.ClientID%> when using a master page
var extender = $find('myExtender_ClientId');
extender.add_collapsed( function() { alert('collapsed'); });
extender.add_expanded( function() { alert('expanded'); });
More details here: http://forums.asp.net/p/1112899/1717195.aspx
You'd want to execute some server side logic to populate stuff in the container that becomes visible. For this you need some AJAJ. This is nothing but some aspx pages written in such a way to render JSON responses back to your browser. But they will be invoked via an XMLHttpRequest object.
Alternatively you can rely on asmx web services, or even page methods to do the work for you. They've to run as script services to do the work for you.
Have a look at this thread for that: http://forums.asp.net/t/1729092.aspx?loading+data+in+the+target+control+panel+of+collapsible+extender+when+Collapse+Expand+control+panel+is+clicked+

Not able to hide the div

I'm not able to hide the in code. I have given Id to div also I have given runat server property to it but on running the code Div is visible . Please help.
My code is like this :
<a href="RoomTypeView.aspx">
<div class="dash-thum-bg" id="rt" runat="server">
<img src="../App_Themes/Akeel/images/thumb-1.gif" />
<span>Room Type</span>
</div>
In code I am writing
rt.visible=false
Try to wrap your div around a panel. Then u can hide the panel in the code behind.
<asp:Panel runat="server" id="divtohide">
<a href="RoomTypeView.aspx">
<div class="dash-thum-bg" id="rt" runat="server">
<img src="../App_Themes/Akeel/images/thumb-1.gif" />
<span>Room Type</span>
</div>
</asp:Panel>
code behind
divtohide.visible = false;
You can use javascript -
function hideMyDiv()
{
document.getElementById('rt').style.visibility="hidden";
}
Add a style -
.hidden {
display:none;
}
Now call it by codebehind

load text into textarea from code behind in asp.net using C#

I've one asp.net page and I want to load text into the textArea control which is in aspx page from into a variable in code behind (C#):
Code behind:
System.Web.UI.HtmlControls.HtmlTextArea Output1 =
(System.Web.UI.HtmlControls.HtmlTextArea)(FindControl("textarea1"));
Output1.Value = Output.ToString();
ASP:
<div style ="width: 78%; float: right; height: 85px; display: block;"
class="message_text_box_left">
<textarea id="textarea1" name="textarea1" cols="30" rows="3"
class="message_text_box" title="Share your Idias here..."
tabindex="1" onkeyup="addrow_fun();"></textarea>
</div>
but it is giving error like
Object reference not set to an instance of an object.
You should add the
runat="server"
attribute to the text area.
Or, preferable you should use the TextBox ASP.NET control and set the TextMode property to TextBoxMode.MultiLine. Example follows:
Code behind:
Output1.Text = Output.ToString();
ASP:
<div style ="width: 78%; float: right; height: 85px; display: block;"
class="message_text_box_left">
<asp:TextBox ID="Output1" Rows="3"
CssClass="message_text_box" ToolTip="Share your ideas here..."
TextMode="MultiLine" />
</div>
Add runat="server" in *.aspx file. Use Innertext property to set the text value.
E.g.
htmlTexarea.InnerHtml = "sample"
Add runat="server" to your control
Check your .designer.cs or codebehind .cs file for textarea/textbox declaration and fix it.
Do not use FindControl function (it is not recursive), get control by ID. textarea1.Value = xxx;
Try casting to HTML generic control and set it's value or change it to use an asp textbox textmode= multiline
If you add the runat="server" attribute you should be able to use the textarea1.innerText directly.
Add runat="server" and get value with InnerText from code behind

how to get wrap text using div tag?

I need to get the "wrap text" in div tag, here is what I'm using:
<div style="width:650px;height:200px;overflow-y:scroll;display: inline-block; writing-mode:lr-tb; word-wrap:break-word;white-space:normal;">
<asp:Label ID="bodyLabel" runat="server" Text=""></asp:Label>
</div>
Can any one please suggest me how to implement this.
Thanks in advance.
what about loosing the label tag , and place your text in the div directly :
<div ID="bodyLabel" runat="server" style="width:650px;height:200px;overflow-y:scroll;display: inline-block; writing-mode:lr-tb; word-wrap:break-word;white-space:normal;">
</div>
and the text will wrap by default in the div.
dont you think its easier ?
Have you tried CSS? See this link.

Categories