How do I make a key binding/shortcut for an ASP.NET button to postback via that button? - asp.net

I'm developing what's intended to be a very efficient UI in ASP.NET.
I want my users to be able to hit ALT-A to postback the form via a particular button. In other words, when they hit "ALT A" the form will post back and the event handler/function associated with a particular ASP.NET button control will run.
How can I do this? I have ASP.NET 2.0/3.5. I also have the Telerik control set at my disposal.
-KF

Use the "accesskey" attribute in HTML.
<input type="submit" accesskey="a" value="Submit">
<asp:Button AccessKey="a" runat="server" ....

Related

using classic asp code inside asp.net?

I have a application that running both classic asp and asp net. inside the classic asp page, I have a combo box and depends on the selection of the combo box I need to do something inside my asp.net page. For instance, if inside my classic asp page, I have a combo box and inside the combo box; book is selected than when I enter a price for book as a zero inside my asp.net page I supposed to get an alert. Is there any way to do that?
asp.net code
if (Convert.ToDecimal(Values["myBookPrice"]) == 0)
{
//You cannot use 0 price for books!
}
Let say that you have some input control on any page, html, asp what ever, with some parametre that you wish to pass to an asp.net page
if the input control have a name attribute like
<form method="post" action="thenewpage.aspx">
<input name="nameOfInput" type="text" id="idofinput" />
<input type="submit" name="btnGo" value="Create Box" id="btnGo" />
</form>
and you have a button that make post back to an asp.net page, then you get that parametre on asp.net side using the Request.Form and the name of the input control as:
Request.Form["nameOfInput"]
If you make a call the page with url parameter, you need to use some kind of javascript to dynamically create the URL string for the call.
The issue that you have here, is that the asp.net page will hit the validation of the page security because is not going to find the page validation informations he needed to secure the page.

How does the textbox + button actually do the searching in asp.net?

I was just curious as to how the textbox + button search actually performs the search to fill up my gridviews, because I couldn't see anywhere that causes the databounds or anything. Is it a post-back thing? How does it work?! o.o
<asp:TextBox ID="SearchBox" runat="server"></asp:TextBox>
<input id="Submit1" type="submit" value="Search" />
Thanks heaps :)
There is no magic binding between a textbox called "searchbox" and a "submit" button in asp.net. The work has to be done somewhere and it's probably just hidden away in some part of the project that you cannot easily find.
In this case, it seems like a normal postback is occurring and some logic in the code behind is interrogating the "SearchBox"'s .Text property.
Just do a project wide search on SearchBox.Text, you should be able to find where the logic is.

ASP.Net PostBack & Button Internal

i worked for long time with windows apps using .net. for last 2 year i am working with asp.net. we often work with asp.net button control. when we click on button then postback occur and right server side event called by asp.net engine. i how link & image button causes postback when user click on those button.
when we work with link & image button then __doPostback js function is called and that causes form submit to server and request the same page and asp.net engine detect which control causes the postback from the hidden input control called eventTarget and invoke right event handler for that control.
but i dont know when we work with asp.net button control like
<asp:Button ID="SampleButton" runat="server"
Text="Submit"
OnClick="ButtonClick" />
when we click button then also form submit but how. i know that in this case __doPostback does not invoke because for button __doPostback is never rendered in the page. so in this case form submit but how asp.net engine detect which button causes postback and invoke right event handler?
how we get the data from textbox like txt1.text when postback occur. is it extracted from viewstate....am i right.
please answer for my 2 question. try to explain here instead of giving any url...thanks.
It's pretty simple with respect to how controls postback. They do it in the same fashion as pure html solutions. There is a Form tag on the page. When the button is pressed it causes the form to submit a postback to the server.
Notice the action target of the form tag, it points to my aspx page
This is all generated by the aspx page itself.
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRk5H5eaMNZp5tsD/GQ2iYj2p8J0as=" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKmxpCiBgKSotaIC5iWtiHNi+oxYiuBULPgr5d0/WFu" />
</div>
<div>
<input type="submit" name="btn1" value="click me" id="btn1" />
</div>
</form>
Yes asp:button works differently by default. It outputs a standard HTML Submit button which posts back to the Action URL specified on the form. It therefore doesn't use events in the same way as other controls.
However if you add a OnCommand and assign CommandName/CommandArgs to the control, it will then cause the same event based callback behaviour as other controls. The same is true of OnClick. I assumed this used the same process as other controls but actually it's different.
It looks like it uses __VIEWSTATE and __EVENTVALIDATION to determine which form posted back, and the name of the submit button id is posted in the form as part of part of standard HTML form behaviuor. This is what is used to trigger the server-side events.

Html control and asp.net web control

i would like to know what exactly the difference between Html control
and asp.net web control. why do we need these two types of controls?
i have placed one html input text ,html button and asp.net text box AND ASP.NET BUTTON on my web page
<input id="Text1" type="text" />
<input id="Button2" type="button" value="button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
when i take view source, both are rendered similarly
<input id="Text1" type="text" />
<input id="Button2" type="button" value="button" />
<input name="TextBox1" type="text" id="TextBox1" />
<input type="submit" name="Button1" value="Button" id="Button1" />
what is the advantage of web control over html control.
I got some links in the internet,but not clear what exactly
they are used for.
http://www.extremeexperts.com/Net/FAQ/DiffBetweenServerandHTMLControls.aspx.
Could any one please explain the difference between these two controls.
First, if you drag an Html control from the Toolbox onto your design surface as in your example, the tag created does not include runat="server". That means it is native Html tag and not a .NET control. A native Html tag without the runat="server" has no server-side functionality. Thus, you could not set the value of the your "Text1" input tag in the code-behind.
Second, once you add the runat="server" to your Html input tag, you convert it from a native Html tag into a HtmlControl which derives from System.Web.UI.Control. Now the question could morph into the differences between something that derives from System.Web.UI.Control and System.Web.UI.WebControl. However, to specifically address your question, let's compare a standard input type="text" control to the TextBox control:
TextBox control can be access from the code-behind where an input control cannot (not easily) which also means that you can wireup server-side events for a TextBox control whereas you cannot with a standard Html control.
A TextBox control automatically saves its value using ViewState.
A TextBox control can be skinned using a Theme and .skin file whereas a native Html control cannot.
A TextBox can render as either an input type="text" control or a textarea depending on its TextMode property.
A TextBox control can participate in validation using validators.
Last but not least, the TextBox control can use control adapters to render differently in different browsers if required. See http://msdn.microsoft.com/en-us/magazine/cc163543.aspx.
Now, all that said, if you do not need any of WebControl capabilities, then using an native Html control is substantially leaner. In your example, you simply dragged two empty controls onto your design surface. If that is all you needed then using the .NET control would be overkill. However, as you start adding AutoComplete and server-side events and such, the full content, Javascript and all, of what gets to the Browser is much larger.
In short HTML controls don't persist their state while Postbacks. On the other hand ASP.Net control provides you to luxury to have their state saved while several Postbacks automatically. Different while using ASP.Net control instead of HTML element is:
<input type="hidden" name="__VIEWSTATE" value="dDwtNTI0ODU5MDE1Ozs+.................." />
This hidden field is auto generated by ASP.Net and it contains all you controls state in value attribute.
The server controls have a runat="server" attribute which enables you to provide server-side logic for these controls in the code-behind. You can also add this attribute to existing HTML controls to gain this same functionality.
The HTML controls are simple controls that correspond directly to HTML elements.
The ASP.NET Web Controls abstract the HTML elements, and generally provide more control over styling (though some would call this a bad thing).

Refresh page in asp.net

I have a webpage, in that page I have a button. How can I refresh the page when clicking on that button?
<input type="button" value="Reload" onclick="window.location.reload(true);" />
However, if the page is created from a postback, you would need to use an asp:Button control instead, and let another postback refresh the page. You also have to make sure that the correct code is executed in the code behind to recreate the correct result.
are you using an
<asp:button />
tag?
If so the page should refresh when the button is clicked by default.
<form>
<input TYPE="submit" VALUE="Submit Information Now" />
</form>
SUBMIT is a TYPE attribute value to the INPUT element for FORMs. It specifies a button that, when activated, submits the information entered to a processing script. If there are multiple SUBMIT buttons in a form, only the one activated should be sent to the form processing script.
When you press button your page must refresh, only not refresh that controls which are in AJAX Update Panel

Resources