accessing an ASP HiddenField within a .JS file [duplicate] - c#

This question already has answers here:
Get the Value of an asp:HiddenField using jQuery
(8 answers)
Closed 5 years ago.
I assign a value to an ASP hidden field within the page load but can't access that value in my JQuery. I added an alert as a test and it comes up 'undefined'. Am I making a syntactic error?
<asp:HiddenField runat="server" id="hfID"/>
hfID.Value = "Test";
alert($('#hfID').Val());

Asp.Net Webforms mangles the id you give it to make sure it's unique on the page. You can use class as a selector or modify your jQuery selector so that it's looking for an id that ends in hfID.
$("[id$='hfID']")

Related

Add tooltip programmatically on asp.net web page [duplicate]

This question already has answers here:
Tooltips for Button elements
(8 answers)
Closed 7 years ago.
I have this code on my project.
string="my string"
how i show this string on a button as a tool-tip. I want this to do programmatically. I want this to do in my code not the design.
i do my codings in asp.net with c# language
Here's how to add the tooltip programmatically
just get the id of the button
<asp:Button id="button1" Text="Submit" runat="server" />
in your code behind:
//do some code to retrieve data from database and store it to this variable
String tooltip = "some text";
button1.ToolTip = tooltip;

How to change the action part of the form element with ASP.NET? [duplicate]

This question already has answers here:
Change HtmlForm action in C# ASP.NET 3.5
(6 answers)
Closed 9 years ago.
The form element on my page created with ASP.NET looks as such (if I do "View page source" from a web browser):
< form method="post"
action="Page.aspx?lang=en-US&pp=10&bi=10"
id="ctl01" enctype="multipart/form-data">
How do I access that form element? I need to remove &pp=10&bi=10 part from the action element?
if you just have one form on the page then try this in your javascript
alert(document.forms[0].action);
to change the action just do it like this
var actionPath = document.forms[0].action;
// your logic to remove unwanted string with the help of string functions in JS
document.forms[0].action = actionPath;
In case you know what is the name of your form then access it like this.
document.forms['YOUR_FORM_NAME'].action
or you can access it with the client id as well if you want consiering your form
have runat="server with it
document.getElementById(....)// Client Id of the form control

C#/asp.net geting error when sending data from one page to another [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Send data from one page to another in C# ASP.Net
Hi I am trying to send data from one page to another in asp.net I found various methods of doing so and am gona try a few to se how they work but I seem to be getting an error on my first attempt.Here is my code:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Go"
PostBackUrl="~/Default2.aspx" />
<br />
I am sending the data from Default.aspx to Default2.aspx.
At the Default2.aspx in the Page_Load method I wrote this to retrieve the data:
if (Page.PreviousPage != null)
{
string txtBox1 = ((TextBox)Page.PreviousPage.FindControl("TextBox1")).Text;
}
From what I read on MSDN this should work but I must be missing something because when I pres the button to send the data and Default2.aspx loads I get an error page that looks like this:
if you use master page for Default.aspx then Page.PreviousPage.FindControl doesn't work. Because when using masterpage, all controls in Default.aspx are placed in ContentPlaceHolder not directy in Form. So you can use below code:
Page.PreviousPage.Form.FindControl("yourContentPlaceHolderID").FindControl("TextBox1");
i assume you use masterpage. Otherwise your first code must work. In addition if you dont use masterpage and textbox is placed in PlaceHolder or Panel, your code won't work as well. FindControl doesnt recursively search in child container controls.
See the link. MSDN
Page.PreviousPage is only available when using Server.Transfer to redirect to a new page. If this is a standard GET or POST, or Response.Redirect then this code will not work.
From your previous page. Use Server.Transfer to be able to access the previous page data.

Read JavaScript display value from HTML file [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
View Generated Source (After AJAX/JavaScript) in C#
Note : I m' not using ASP.NET and i use a c# Console project.
With a simple html document :
<script type="text/javascript">
eval(function(p,r,o,x,y,s){y=function(c){return(c<r?'':y(parseInt(c/r)))+((c=c%r)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(o--){s[y(o)]=x[o]||y(o)}x=[function(y){return s[y]}];y=function(){return'\\w+'};o=1};while(o--){if(x[o]){p=p.replace(new RegExp('\\b'+y(o)+'\\b','g'),x[o])}}return p}('j=D^C;b=3;h=1;r=7;t=B^E;p=9;g=F^A;f=0;l=5;a=G^I;q=y^u;o=w^z;s=6;d=4;k=2;n=8;m=x^v;i=H^L;e=W^U;c=X^V;J=f^j;S=h^i;M=k^g;T=b^a;K=d^e;N=l^m;O=s^t;R=r^q;Q=n^o;P=p^c;',60,60,'^^^^^^^^^^Three4Two^Seven^One3Nine^Nine^Four4Three^Zero^OneTwoSix^Three^FourSixFive^Five8Four^One^Two^One2Eight^Five^ZeroThreeZero^Six^Nine0Seven^Four^Eight^SevenNineOne^8080^8888^10448^7095^12181^3129^88^11687^8090^3394^1337^3885^9893^12222^9090^ZeroOneNineThree^SixOneTwoOne^8000^ThreeEightThreeTwo^OneOneSixSeven^FourThreeEightZero^Eight2FourEight^Seven0ZeroNine^OneEightFiveSix^EightTwoSevenFive^Four0OneFour^808^1080^11238^10637'.split('\u005e'),0,{}))
document.write((Seven0ZeroNine^ZeroThreeZero));
</script>
Which Display simply "8"
I would like to get this "display" value. I need certainly Webrowser which decodes JavaScript.
WebBrowser web = new WebBrowser();
web.Navigate(#"c:\1.html");
Open a browser console (google it) and try:
console.log("string goes here")

passing parameter in asp.net c# [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Passing data between asp.net pages
how to pass value of TEXTBOX from one page to another page in ASP.NET c# I need, not by using URL string query method. I do need passing from one page to another without passing values by URL.
Use the session state.
Session["TextBoxValue"] = TextBox1.Text;
Then, retrieve it on the other page:
string val = Session["TextBoxValue"];
you can create a form in the first page, this form contains your required parameters and use an action redirect to another page like in this example:
<form method="post" action="yoursecondpage.aspx">
<input ... />
</form>
Another way is using a Server.Transfer("mySecondPage", true), in the second page, on Page_Load event you can cast "PreviousPage as MySecondPage" and get properties .

Categories

Resources