I am getting below text from database with href as null.
You also have to click on this link .
This text I am assigning to the label when page loads.
My requirement is when I click the "link" I need to redirect to certain page. Where should I assign the href value and how?
<script>
var s = document.getElementByTagName("a");
s.href = ""; // here give the href value
</script>
If you are using jQuery you can set the href using the following code:
$("a").attr("href", "http://stackoverflow.com");
In the aspx page you can write the following line to create a placeholder
<div><%= linkValue %></div>
And in the code behind create a global variable
string linkValue = "You also have to click on is <a href='' target='_blank'> link </a>";
/* Set the page URL where you want to redirect the page. in your case get the value from database. */";
I think this is what you want to do. It was not completely clear from the question.
Updates:
In case you have multiple links in the page you need to create the link along with label.
See the code below
HyperLink link1 = new HyperLink();
link1.Text = "LINK HERE";
link1.NavigateUrl = "http://somedomain.com";
And add to the container like this
container.Controls.Add(link1);
document.getElementById('myAnchor').href="http://www.google.com";
Simple enough :)
In case, you also want to Change URL and text of the hyperlink...
<html>
<head>
<script type="text/javascript">
function myHref(){
document.getElementById('myAnchor').innerHTML="Visit Google"
document.getElementById('myAnchor').href="http://www.google.com"
}
</script>
</head>
<body>
<a id="myAnchor" href="http://www.java2s.com">Visit Java2s</a>
<form>
<input type="button" onclick="myHref()" value="Change URL and text">
</form>
</body>
</html>
Source: java2s
Related
I have a Value coming from model that is relatively a huge html String. It also has a token that needs to be replaced with a value from Angular. I am trying to see how to get both of ends meet.
my Html
<h2 class="sub-title"> #Model.WelcomeText </h2>
Now this Welcome text is a relatively a html string that has a token. Something like this
"Hi ##Name , Welcome to our Website. Click <a href='#'> here </a>
for more details. <small> For more details please visit blah blah
</small>
Now i need to replace ##Name with a model value in my controller- $scope.Name
I tried
<h2 class="sub-title" ng-init= $scope.welcomeText('#Model.WelcomeText') </h2>
and then in my controller
function welcomeText(str)
{
return str.replace('##Name',$scope.Name);
}
But it breaks in the html itself because of $scope.welcomeText has invalid values inside ng-init
Any pointers on how to achieve this? The Model.Title is from a Sitecore CMS. I dont have that value in JS
I ended up doing this. Not sure if this is the ideal solution but atleast it works.
//Added a div with hidden class to get the value.
<div class="hidden" id="inp-title-server" /> #Model.Title </div>
<h2 class="sub-title" data-ng-bind-html="$scope.header"></h2>
Then in my controller,
var title = $("#inp-title-server").text();
$scope.header = title.replace('##Name', $scope.Name);
You can simply use replace function of string.
angular.module("app",[])
.controller("ctrl",['$scope',function($scope){
$scope.WelcomeText = "Hi ##Name , Welcome to our Website. Click <a href='#'> here </a> for more details. <small> For more details please visit blah blah </small>";
$scope.UserName = "ABC";
$scope.WelcomeText = $scope.WelcomeText.replace("##Name",$scope.UserName);
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<html>
<body ng-app="app" ng-controller="ctrl">
<h4 class="sub-title" ng-bind="WelcomeText"> </h4>
</body>
<html>
One my designer send some webpage where he used Html(div,Li) CSS for making Drop down list
<div class="frmcmpstn fl">
<a class="btn fl cll" href="#">Are you an Hwp/Family Office or an Institutional <img src="images/dd_arow_ico.png" /></a>
<ul class="signupdd_dd" style="display:none;">
<li>New Delhi</li>
<li>California</li>
<li>Gurgaon</li>
<li>North East America</li>
<li>North America</li>
<li>South Africa</li>
</ul>
</div>
now my problem is I have worked in Asp.net I dont know javascript or JQuery and
I know that is possible in java script or JQuery
Can any one tell me how can get selected item (in javascript or JQuery )....?
I think you mean:
<script type="text/javascript">
$('.signupdd_dd li').on('click',function(){
var $selectedLi = $(this);
//then do some stuff e.g
$selectedLi.addClass('selected');
});
</script>
</body> //-> don't add this line but search in your html code this tag and put <script> just before
Or target the tags:
$('.signupdd_dd li a').on('click',function(){...});
Attach an event handler to the click event for each of the anchors a. The event handler will have the element assigned to this which you can use to get the different element properties.
$(".signupdd_dd li a").click(function(e){
e.preventDefault();
$(".chosen").removeClass("chosen");
$(this).addClass("chosen");
alert($(this).text());
});
You may want to add a class to the a that is clicked for later processing. The event handler should also prevent the default action of the anchors click handler so that navigation does not occur.
Working Example: http://jsfiddle.net/vZkDp/
I'm creating an online application form.
In front page, There are First Name, Last Name, Email etc... form inputs. What I want is that
if user fills the form and click on the submit, I want to show him the print preview page with values which user filled... Is it possible? I'm using ASP.Net C#
If you can use jquery this code is good
$(document).ready(function () {
window.print();
});
and you can see these
http://www.designplace.org/tutorials.php?page=1&c_id=27
http://www.alistapart.com/articles/goingtoprint/
https://web.archive.org/web/20211029043752/https://www.4guysfromrolla.com/webtech/061103-1.shtml
If you can use javascript, then try this
<script type="text/javascript">
function CallPrint(strid) {
var prtContent = document.getElementById(strid);
var WinPrint = window.open('', '', 'letf=0,top=0,width=850,height=800,toolbar=0,scrollbars=1,status=0');
WinPrint.document.write('<html><head><title>Popup</title>')
WinPrint.document.write('</head><body>');
WinPrint.document.write('</body></html>');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
}
</script>
Take a print button on the page
<input id="btnPrint" type="button" value="Print" runat="server"
onclick="javascript:CallPrint('divPrint')"/>
and Place your Controls which are to be printed within a div
<div id="divPrint">
//Your controls
</div>
I am building a WebMatrix-based site, and I overlooked something. Something that just didn't occur to me.
My site is made up so that each page refers to the _SiteLayout.cshtml page for the header and footer. For example:
_SiteLayout.cshtml:
<html>
<head>
</head>
<body>
<div id="Container">
<div id="heading">
<input type="text" name="search" value="search" id="searchbox" />
</div>
#RenderBody() <!-- display Default.cshtml content -->
<div id="footer"><p>stuff here</p></div>
</div>
</body>
</html>
Default.cshtml:
#{
Layout = "~/_SiteLayout.cshtml";
}
<p>
I want to display search results in the Default.cshtml (homepage) page, but I don't know how to if the search form is inside the SiteLayout page. How to do this?
</p>
So, my question is I want to display search results in the Default.cshtml (homepage) page, but I don't know how to if the search form is inside the SiteLayout page.
How do I go about doing this?
You'll need to post the information in that search input to the server. Once you have the data back, you can use it to target an HTML element you know will be in the subviews.
This article from the jQuery docs helped me out. My data was coming from a JSON response, but the example shows how you can use jQuery to take the results response and add it to a specific element (in this case, the <body>, but you could just as easily create a div with an id of "search-results" and target it with #search-results):
$.getJSON('ajax/test.json', function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body'); // Here, you could append your items to #search-results
});
Then it would be up to all the views to contain a section with an ID of search-results, but if it didn't exist, then the data just wouldn't show up anywhere. The script should be in a separate file and referenced in your main site layout.
Hello I am trying to read a textbox(runatserver) after is gets populated form the server into a javascript variable,but it gives me a console error that "can't read form NULL" however the text box is populated by the string I want to read
this is my text box:
<form runat="server">
<asp:TextBox ID="ServerSideTextBox" runat="server" />
</form>
This is how I am populating it in C#:
ServerSideTextBox.Text= Object_JSON_Class.JSON_DataTable(dt);
it gets the right data also shows the right data string but the PROBLEM is when I try to read the value of the text box like this:
var oServerSideTextBox= document.getElementById("ServerSideTextBox");
var oServerJSON_String=eval("("+oServerSideTextBox.value+")");
I get a console error that I can't read form NULL,but the text box does have the string I want to read into javascript variable,please help
var txtToIncr = document.getElementById('<%=ServerSideTextBox.ClientID%>')
Check out this link, about reading ASP.Net controls through javascript
Try this:
var oServerSideTextBox= document.getElementById("<%=ServerSideTextBox.ClientID%>");
If that does not work, try something like this:
var oServerSideTextBox= document.getElementById("<%=ServerSideTextBox.ClientID%>_text");
Components are assigned different ID's when rendered by the client's browser. You can take a look here for more information.
put this on yout textbox ClientIDMode="Static"
Your server textbox's ID will be different if you use it in a master page structure , try finding its id.Because its actual id might be something like this ctl00_ContentPlaceHolder1_ServerSideTextbox.Check that.
Assign a class to yout textbox then try this to find the id.
$('.textbox').on('blur', function() {
var error = this.id;
alert(error);
)};
Reading the comments. I think you're referring to the wrong textbox-ID..
So I made a small test-thingy: this should work.. If not look into the source from your HTML - there you can see the ID.
<script type='text/javascript'>
function testvalue() {
var oServerSideTextBox = document.getElementById('<%=ServerSideTextBox.ClientID%>');
if (oServerSideTextBox == null) {
alert('this is null');
}
else {
alert(oServerSideTextBox.value);
}
}
</script>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="ServerSideTextBox" runat="server" Text="Testvalue" />
<input type='button' onclick='testvalue();' value='Click' />
</div>
</form>
</body>