Refresh page in asp.net - 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

Related

simple html5 button trigger postback in asp.net webform

I have a simple HTML button to trigger jquery function but when i add this button to webform it triggers post-back.
Play
I tried adding OnClientClick="myfunction(); return false;" but it sill postback.
How can i use simple button without postback
Try adding stoppropagation() to your function
If you are using input tag with type="submit" or button tag with type="submit" than clicking it will cause the page to submit. So you may need to use type="button".
<input type="button" onclick="yourfunction()" value="SomeValue" />

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.

changing the PostBackUrl in ASP.net after a file download

I have a ASP.net which allows users to select a number of inputs and dropdown lists to filter the report and to download an Excel report after pressing a button on that same form.
The page can be used mulitple times, by changing the inputs and pressing the download
button each time.
The button should be posting back to the hidden IFRAME to a separate webpage, but I am
unable to change the target for the form on the fly as needed.
<form runat="server" method="post">
<asp:Button runat="server" id="DownloadToExcel" TabIndex="-1" Text="Download To Excel" UseSubmitBehavior="False" PostBackUrl="report.aspx" />
</form>
<iframe style="hide" id="output" src=""></iframe>
Additonally, when I download the file when pressing the "DownloadToExcel" button, the file downlodads as expected. However, any additional postbacks including updating the screen are posting back to report.aspx and not filter.aspx.
How do I correct the postback so it only postbacks once to download the file, and then change it back to the original page so the screen can continue to be used to filter and download a second report.
This may also eliminate the need of the IFRAME as well.
I solve the problem my adding PostBackURLs to all the submit buttons directly.
One for the Excel download that goes to report.aspx and the other for the postback on the page for filter.aspx.
It appears that if the postback is changed, in this case to report.aspx, it reuses the pathname for any subsequent postbacks, unless defined explicity, for each time you wish to postback.

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

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" ....

When does an HTML input tag post back on enter?

I have a couple of asp.net pages with TextBox controls on them. Some of them postback on enter (within a TextBox control) and others don't. For the life of me, I can't figure out why or why not...
I don't think this has anything to do with asp.net. Not using ajax etc. Tried playing with a very simple html page and still can't figure it out.
Maybe within or not within a <form> tag? But all my asp:textbox controls are within the standard form tag and some do and some don't. Not related to autoPostback from what I can see.
EDIT:
Sample markup which causes a post back:
<html>
<body>
<form>
<input type=text />
</form>
</body>
</html>
I have asp.net pages that definately don't post back. The code is extensive and I can't figure out why not.
EDIT2:
How can I prevent a postback?
If you only have one textbox and don't wan't this behavior, you could always put a hidden input on the form.
<html>
<body>
<form>
<input type="text" ></input>
<input type="text" style="visibility:hidden"></input>
</form>
</body>
</html>
I've tried this in IE7 and FF3 and it works.
Generally most web browsers will detect when a form has only one textbox and will automatically submit the form when enter is pressed.
If you have multiple text boxes or multiple form buttoms, the behaviour varies. ASP.Net has the "defaultButton" mechanism for buttons, meaning you can specify which button is the submit button for a given panel in the case of the enter key being pressed. You could check out this post for more information on setting up your forms to correctly post back.
As Boo mentioned, this won't be triggered by multi-line textboxes.
If the behaviour is really crappy in your form between browsers, you may need to look at a javascript solution to catch the enter key being pressed, and "manually" submitting the form via javascript.
If the textbox control is set to autopostback it will postback on every keypress (thus allowing the firing of the TextChanged event).
Next, text boxes that have their Multiline property set to false will appear to postback on Enter.. what is actually happening is a form submit as defined by the behaviour within the browser.
Boxes that have Multiline set to true will not cause a form submit on Enter.

Resources