How do I edit values in a web-browser. .NET - asp.net

<a id="ctl00_ctl00_cphBanner_BannerAlertsLoginView_BannerAlerts_Authenticated_rbxBanner​Alert_rbxAlerts_RobuxAlertCaptionHyperLink" class="RobuxAlertCaption tooltip-bottom" href="AccountBalance.aspx" original-title="ROBUX">740</a>
How do I edit the 740. For example, If button1 is pressed then. 740 textbox1.text.
How do I edit the webbrowser HTML with the text box value

Try this
JQUERY
$("#<%= txtName.ClientID%>").val("Test");

If if you want to do it after postback, There is a few solution
Make your tag as .net registered;
<a id="hrefReplace" runat="server"></a>
And change attribute like
hrefReplace.Width = 775;
Post a Javascript to your App
string jScript;
jScriptValidator="<script> $("#<%= txtName.ClientID%>").widht(775);)";
Page.RegisterStartupScript("regJSval",jScriptValidator);

Related

How to open a link like www.gmail.com from code?

I want to open an URL like gmail.com when a user clicks on a button. How can I open this link in new tab from code (I want to read link from database)?
You can use:
Response.Redirect
Method in ASP.NET to navigate to another web page.
call JavaScript from Page Behind Code Like this.
Page.ClientScript.RegisterStartupScript(this.GetType(),
"onLoad", "openNewWindow()", true);
<script language="JavaScript">
<!-- hide
function openNewWindow() {
popupWin = window.open('http://webdesign.about.com/',
'open_window',
'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0')
}
// done hiding -->
</script>
you can also do it using window.location("http://www.yourpath.com")
As suggested before me use
Response.Redirect("http://www.gmail.com")
this should work as the method is designed also for absolute urls. Do not leave the http:// prefix.
<input type="button" onclick="openlink()"/>
<script>
function openlink()
{
document.location.href = "http://www.gmail.com";
}
</script>
just execute the below line on button click
window.location="http://www.google.com";

How can I add a random number to an ASP.NET menu item url on each click

One step to prevent caching (in addition to adding the appropriate headers etc..) is to add a random number to the end of my URLs.
I'm using an ASP.NET menu and would like to add a random number to each menu item's navigate URL as it is clicked.
I can do this in the MenuItemDataBound event, but haven't had much luck doing the same with the MenuItemClicked Event.
Answer (can't answer my own question for 8 hours, and I don't have time to wait that long so here's my server side solution.)
To do this server side, I've had to remove the sitemap and the databinding from the menu.
I simply added all of the items from the sitemap as menuitems to the items collection in the menu markup removing the url property. The key here is removing the url property.
<asp:menu>
<items>
<asp:menuitem Text="Home" ToolTip="Go Home" Selectable="True" />
</items>
</asp:menu>
Then in your code behind you can handle the MenuItemClicked event (which should now fire, because there is no longer a navigateurl in the markup).
In the MenuItemClicked event codebehind I simply do the following:
string TimeStamp = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
// get iframe control - must have 'runat=server' attribute
HTMLControl display = CType(this.FindControl("display"), HTMLControl);
// dispatch menuitem
switch (e.item.valuepath)
{
case "Home":
display.attributes("src") = "home.aspx?=" + TimeStamp()
break;
.
.
.
}
This is the server side solution with an iframe.
I don't know if you're considering client-side URL manipulation as an option, but running this little bit of JavaScript on each page load would give you the behavior you're looking for by appending a timestamp to each of the links. You can modify it to target links in a specific area/div of the site, but this example will change them all:
<!-- include the jQuery library -->
<script type="text/javascript">
$(function(){
var time = new Date().getTime();
$('a').each(function() {
var append = (this.href.indexOf('?') > -1 ? '&' : '?');
$(this).attr('href', this.href + append + 't=' + time.toString());
});
});
</script>
Since every time the page loads the timestamp will be different, you should always get a unique set of links.
EDIT Here's a working jsFiddle demoing the behavior: http://jsfiddle.net/2HzqU/2/
I don't think that's the best solution. Have you tried using something like this:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();

Whats the difference if I set hidden field value through html anchor OR asp.net linkbutton?

The problem is, I have a set of links onclick of those links I am setting the linkId into a Hidden field. First my link were asp:linkbutton ans onClientClick I was setting the hiddenfield value.that time I was able to get the hidden field value from code behind but when I changed my links to HTML anchor and onClick I set the hidden field value , I am not getting hidden field with blank. when I debug JavaScript it is perfectly setting the hidden field value but why I am not getting it in code behind---my code-
<a href="./ContentPage.aspx" data-flexmenu='flexmenu1' onclick="javascript:setPageLinkId(1);">
<script type="text/javascript">
function setPageLinkId(lnkPageId) {
debugger;
alert(lnkPageId);
document.getElementById('<%=hdnSelectedLink.ClientID %>').value = lnkPageId.toString();
}
</script>
//code behind- here I get blank hidden field
if (hdnSelectedLink.Value != null && hdnSelectedLink.Value != "")
{
GetLinkPage(Convert.ToInt32(hdnSelectedLink.Value));
}
Whats the problem ,Please suggest?
My theory is that the click on the anchor doesn't cause a postback to the page. Rather a HTTP GET Request to "ContentPage.aspx" is issued, meaning that any form values are not posted to the server.
You need to use a control that causes a postback to the page...for example ASP:LinkButton as you had before.
#Ozzy you were right dude.I used this in my javascript-
document.forms["aspnetForm"].submit();
its working fine now.

How to get the selected Date from the calendar control?

Hai ,
I am creating a DatetimePicker User control. I just want to know how to get the selected date of the calendar (asp.net control) control using jQuery. I used this code, but it's wrong.
$(document).ready(function() {
$(".UserCalender").click(function () {
var a = $('.CalenderDiv:selected').text();
alert(a);
});
});
What's wrong with this?
You won't be able to do like this. There is no :selected selector for an anchor tag. It works only for <option> elements. What you can do is to attach an event hanlder to each anchor ag and use the text() method. Something like
$("#Calendar1 a").click(function(){
alert ( $(this).text() );
return false;
});
But why do you want to do this. By doing like this you will get only the text inside the anchor tag and not the whole date. To get the whole date you will have to perform additional work.
If you want to manipulate the selected text then you can use any datepicker plugin from jQuery.
See jQuery UI Datepicker

How do I add custom hyperlinks to a webpage

I want to add a hyperlink to a social bookmarking site om my webpage which requires me to include the name of the page it is being sent from.
Example of what I am trying to achieve:
Current page is:
http://www.testpage.com/testpage.aspx?test=34
Hyperlink I want to create on the above page:
http://www.stumbleupon.com/submit?url=http://www.testpage.com/testpage.aspx?test=34
What is the easiest way to programmatically add this customised hyperlink to a webpage?
Assuming that you have a hyperlink like that :
<asp:HyperLink runat="server" ID="myLink" Text="stumbleupon"></asp:HyperLink>
At server side :
string currentPagesUrl =
HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri);
myLink.NavigateUrl = string.Format("http://www.stumbleupon.com/submit?url={0}",
currentPagesUrl);
Or an alternative way (this one is easier I think) :
<a href="http://www.stumbleupon.com/submit?url=<%= HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri) %>" target="_blank">
stumbleupon 2</a>
I second Canavar's answer. You might want to also URL encode the currentPagesUrl string when building the hyperlink:
myLink.NavigateUrl = string.Format("http://www.stumbleupon.com/submit?url={0}",
Server.UrlEncode(currentPagesUrl));
Using jQuery:
$(document).ready(function(){
$("a.stumblethis").each(function(){
$(this).attr("href", "http://www.stumbleupon.com/submit?url="+$(this).attr("href"));
});
});
This will convert all links that have a class of "stumblethis".

Resources