ASP.NET C# Input TextBox value by pressing Enter key. Huh? I want to get the value of the textbox without click on the submit button. But getting the textbox value by just pressing enter key on keyboard. How am I going to do so? The page just refresh if I press enter key. I want the enter key link to the submit button. Therefore, whenever I press enter key, I will get the textbox value.
Here is the solution to get it done. By adding defaultbutton variable in form or asp:Panel will solve it.
Code example
<form id=”form1″ defaultbutton=”Button1″ runat=”server”>
<div>
<asp:TextBox ID=”TextBox1″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button1″ runat=”server” Text=”Button” OnClick=”Button1_Click” />
<br />
<asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label>
<asp:Panel ID=”Panel1″ defaultbutton=”Button2″ runat=”server”>
<asp:TextBox ID=”TextBox2″ runat=”server”></asp:TextBox>
<asp:Button ID=”Button2″ runat=”server” Text=”Button” OnClick=”Button2_Click” />
<br />
<asp:Label ID=”Label2″ runat=”server” Text=”Label”></asp:Label>
</asp:Panel>
</div>
</form>
23 Sep
Posted by Jayce as Programming, Web
CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files… ‘Access is denied.’
Do you face this problem lately? I did. I have problem to run ASP.NET web application on a fresh installed server. It cannot run ASP.NET even I install .NET Framework 3.5. Web application can be loaded after I register ASP.NET into IIS by using “aspnet_regiis.exe -i -enable“.
However, I faced the problem statement above. So what is the solution? It have something to do with file permission. Just follow below steps to fix it.
Grant full control to two users of your system “Network Service” and “YourComputerName\IIS_IUSERS” on the following folders.
1. C:\Windows\Temp
2. C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Restart IIS and try run your web application again.
Hope this guide will help.
How to change GridView HeaderText? I have been looking for this solution for days. Finally, I got the answer. Yeah… ![]()
Here is the code…
GridView01.Columns[0].HeaderText = “HeaderName”;
This will change the GridView’s first column to “HeaderName”.
Why ASP.NET Master Page Name Mangling is important? I did not know about it before I encounter some issue with JavaScript ID naming. I cannot run the JavaScript code due to wrong ID name.
For example, you create a button with ‘Button1′ as its ID. Its name will still be ‘Button1′ under normal HTML. However, its name changes if you use ASP.NET MasterPage. It will change to ‘ctl00$Button1′ from ‘Button1′. You can find that out when you see its source code using Internet Explorer / Firefox view source function.
Here are some source code to pass DateTime JavaScript value to ASP.NET in C#. It is used to get client side date and time. It is useful for those who need to display client date and time instead of hosting server date and time.
Put these codes at HTML
<input type=”hidden” id=”hdClient” runat=”server” />
Put these codes at ASP.NET code behind
At Page_Load
Page.RegisterClientScriptBlock(“1″,
“<script type=’text/javascript’>
function goforit()
{var now = new Date();
var offset = now.getTimezoneOffset();
document.forms[0].hdClient.value = -offset}
</script>”);ClientScriptManager manager = Page.ClientScript;
manager.RegisterStartupScript(this.GetType(), “CallSomething”, “goforit();”, true);
And…
Label1.Text =
DateTime.Now.ToUniversalTime().AddMinutes(double.Parse(Request.Form["hdClient"])).ToString();
Hope this will help.