I want to implement localisation in web forms. For this I have created resource files under App_GlobalResourses.
At my web forms both html and asp.net server controls exist. I have replaced both text as shown below respectively:
<%= Resources.Resource.Email%> (for html controls)
and
asp:Button ID="Button2" runat="server" Text="<%$ Resources:Resource, Email %>" /> (for asp.net controls)
Now I have a dropdown for switching culture. When I change culture, all html controls text changed according to new culture but asp.net server controls text is not changing.
How can I change asp.net server controls text.
I had the same problem.
what I did:
(I believe there are better solutions but I did not find them).
I have an asp:button named btnSubmit. its text comes from "Resources.MyResource.SubmitText".
in document.ready() function I add the follwing line:
$("#<%= btnSubmit.ClientId %>").val("<%= Resources.MyResource.SubmitText %>");
so when the page is ready the value of my button is changed to the current resource,
and it works perfectly.
I have a few submit buttons in my ASP.NET page. Everything works fine, but when a user hits enter button always the first submit button works. I want to fire each submit button with corresponding fields but cannot have multiple forms. Is it possible to group them without using forms?
You don't need forms, just wrap the related controls in their own panels and use the Panel.DefaultButton property.
Use the DefaultButton property to indicate which button gets clicked
when the Panel control has focus and the user presses the ENTER key.
The DefaultButton can be set to the identifier for a Button control or
any control that implements the IButtonControl interface except a
LinkButton control.
Please use DefaultButton property like this
<asp:Panel runat="server" DefaultButton="bt1">
<asp:TextBox runat="server" />
<asp:Button id="bt1" Text="Default" runat="server" />
</asp:Panel>
Please refer here :- ASP.NET DefaultButton Property
Earlier, I had a button control on my web page. but now I changed it to a CSS button suting my needs. Before this, the button control was performing code-behind operation but now I switched to this CSS button.
Delete profile
How can I accomplish the same code-behind process now?
You can change the anchor to be a server side control (turning it to a HtmlAnchor control) and use the ServerClick event:
Delete profile
To keep it simple, you could use a linkbutton and get the server side click event
<asp:LinkButton ID="lb1" runat="server" onclick="lb1_Click" CssClass="cssClass" />
In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or Open in new window.
How do I show those menu items?
Code example:
<asp:LinkButton id="lbnkVidTtile1" runat="Server" CssClass="bodytext" Text='<%#Eval("newvideotitle") %>' />
From the docs:
Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.
As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.
Depending on what you are trying to do you could either:
Use a HyperLink control, and set the Target property
Provide a method to the OnClientClick property that opens a new window to the correct place.
In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
Here is your Tag.
<asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>
Here is your code on the code behind.
LinkButton1.Attributes.Add("href","../Test.aspx")
LinkButton1.Attributes.Add("target","_blank")
Hope this will be helpful for someone.
Edit
To do the same with a link button inside a template field, use the following code.
Use GridView_RowDataBound event to find Link button.
Dim LB as LinkButton = e.Row.FindControl("LinkButton1")
LB.Attributes.Add("href","../Test.aspx")
LB.Attributes.Add("target","_blank")
try by Adding following onClientClick event.
OnClientClick="aspnetForm.target ='_blank';"
so on click it will call Javascript function an will open respective link in News tab.
<asp:LinkButton id="lbnkVidTtile1" OnClientClick="aspnetForm.target ='_blank';" runat="Server" CssClass="bodytext" Text='<%# Eval("newvideotitle") %>' />
This is not perfect, but it works.
<asp:LinkButton id="lbnkVidTtile1" runat="Server"
CssClass="bodytext" Text='<%# Eval("newvideotitle") %>'
OnClientClick="return PostToNewWindow();" />
<script type="text/javascript">
function PostToNewWindow()
{
originalTarget = document.forms[0].target;
document.forms[0].target='_blank';
window.setTimeout("document.forms[0].target=originalTarget;",300);
return true;
}
</script>
LinkButton executes HTTP POST operation, you cant change post target here.
Not all the browsers support posting form to a new target window.
In order to have it post, you have to change target of your "FORM".
You can use some javascript workaround to change your POST target, by changing form's target attribute, but browser will give a warning to user (IE Does), that this page is trying to post data on a new window, do you want to continue etc.
Try to find out ID of your form element in generated aspx, and you can change target like...
getElementByID('theForm').target = '_blank' or 'myNewWindow'
When the LinkButton Enabled property is false it just renders a standard hyperlink. When you right click any disabled hyperlink you don't get the option to open in anything.
try
lbnkVidTtile1.Enabled = true;
I'm sorry if I misunderstood. Could I just make sure that you understand the purpose of a LinkButton? It is to give the appearance of a HyperLink but the behaviour of a Button. This means that it will have an anchor tag, but there is JavaScript wired up that performs a PostBack to the page. If you want to link to another page then it is recommended here
that you use a standard HyperLink control.
It throws error.
Microsoft JScript runtime error: 'aspnetForm' is undefined
<asp:LinkButton ID="LinkButton1" runat="server" target="_blank">LinkButton</asp:LinkButton>
Use target="_blank" because It creates anchor markup. the following HTML is generated for above code
<a id="ctl00_ContentPlaceHolder1_LinkButton1" target="_blank" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')">LinkButton</a>
I have some code on a User Control that looks like this:
<asp:PlaceHolder id="ph1" runat="server">
<script type="text/javascript">
jQuery(function() {
doSomethingAwesome();
});
</script>
</asp:PlaceHolder>
I want to get the contents of the PlaceHolder control. I'm trying to get it in the OnPreRender of the page this control is on. I would have expected that the contents of the PlaceHolder would be be a single Literal control, but the Controls collection is empty.
How can I get the contents of the PlaceHolder control on the server side?
Literal content doesn't exist on the server because it's not in a server control.
If you need to make the script visible on the server, you'll need to explicitly put it inside a server control with the "runat=server" property set.
To get contents on client side you can do
$('#ph1').html()
If using naming containers which is likely because of user controls
$('#<%=ph1.ClientID%>').html()