Calling postback in asp.net programmatically - c#

I am using spgridview with spgridviewpager in update panel. I need to postback using c# in aspx page. I used button field in the spgridview. When i clicked on the button field, i need to raise the postback event using c# or javascript.
Can any have an idea how to do it programmatically?

Since there are some quite good articles on the web explaining this, let me answer your question with a link:
How to call Postback from Javascript

I think you can use triggers after the content template of update panel.
One more simple suggestion:
If you just want to cause a postback and to do nothing after postback, simply double click the button in the design view, you will get an onbuttonclick event generated in the code behind page. Don't write anything inside that button click event block. The page will get posted onclicking the button. If you want to implement something, write the code inside the button click event.

go to the button property u will find postback url ..
if not then use rowCommand to get the button event rise

Related

Prevent button_click event in page refresh in c#

I want to prevent button_click event in page refresh.
I have searched but can not get any solution relevant for me.
I have found this one:
http://www.dotnetspider.com/resources/42823-How-Avoid-Re-Submitting-Data-Page-Refresh.aspx
But i do not need to go inside button_click event in page refresh.
Response.Redict("") also not relevant here as i am returning label text after succesful button_click.
What you looking for is not so simple.
The solution you can use for sure is the Post/Redirect/Get design pattern
or use some code that tries to detect the refresh of the page on:
http://www.codeproject.com/KB/aspnet/DetectingRefresh_.aspx
http://dotnetslackers.com/community/blogs/simoneb/archive/2007/01/06/Using-an-HttpModule-to-detect-page-refresh.aspx

IE7 Dropdownlist not displaying on 1st click following className change onfocus

I am trying to change the CSS class of a dropdownlist on its onfocus event to change its background colour.
When the user clicks on the the dropdownlist, the CSS class is changed (the backgound colour is changed), but the list of options is not displayed until it is clicked again.
This is happening in IE7. It works fine in Firefox.
The only advice I have found anywhere on this problem suggests also using the onfocusin event:
http://www.eggheadcafe.com/software/aspnet/34297064/open-dropdown-list-only-with-double-mouse-click.aspx
but this did not have any effect.
The onfocus event is attached to the dropdownlist in the code behind:
ddl.Attributes.Add("onfocus", "setCssClass();");
The javascript the sets the class:
ddl.className = "Class1";
Please help!
Thanks to anybody who looked at this, but I have found the answer myself.
The problem was only occuring when the focus was coming from a few particular controls. These controls had onblur events that also set the class of the dropdown.
I had assumed that these onblur events would run before the onfocus/onfocusin, but it seems that this is not the case. The onblur events then seem to close the dropdownlist when applying the class change.
Anyway, I now check which control has the focus on these onblur events, and if it is the dropdown list, I don't run the main logic within the onblur and all now works as expected.
Putting in a hard coded "onfocus" event will force you to have 2 clicks when using Internet Explorer. It's a known quirk with IE. Although this solution isn't perfect. If you have an alert for example inside this anonymous function in the .focus() callback, you still have to click the dropdown twice. You just have to get creative.
As a workaround, just use the jQuery .focus event.
jQuery([dropdownlist object]).focus(function() {
... put code here
});

Button click is again fired on reload

When page is reloaded it again goes to last event(e.g. Button click).Is there any way to prevent this?
If you are reloading the page by 'refreshing' (F5), and clicking to accept the resubmission of values, the button click event firing again is by design.
If it's something else, we need much more information to help.
Try to add a Response.Redirect to the current page in the end of your event handler.

Generating event on .cs page by double click on the design view of .aspx page

I am developing a web application in asp.net and c#, now in a particular aspx page whenever I doubleClick(design view) on a button or on a drop down list, instead of going to
public void btn_click event or DropDown_SelectedIndexChanged event, the cursor points to protected void Page_Load only. Strange!! any remedy?
Not a fix for your VS misbehaving, if it is doing so. But this will help you wire up your events and perhaps notice anomalous event assignments:
Select the control in question, right-click>Properties, switch to the 'events' tab (lightning bolt) and either enter the name of a method or simply double click the empty space to generate an event handler in your codebehind.
This is also where you will see if Page_Load is already, for whatever reason, assigned to the event you are having trouble with.
HTH
May be both your btn_click event and DropDown_SelectedIndexChanged event delegates have Page_Load as the method. Check your events tab for button and dropdown.
this happens to me when I have my project running in debug mode and forget to stop it before editing my code. Long shot, but sometimes the obvious things are the things we overlook :)

DataList ItemCreated event

I have a datalist in my aspx page. In the datalist, there are images displayed. When I click on an image, a bigger version of the image appears in a popup, and in this popup there is a button. On that button, I want to react to a click even without postback. What I'm doing now is not working every time. I am using go for the item_created event and __dopostback(btn.id,"onClick").
The item_created event fires when I click on the ok button on the div that displays the image.
If you mean that ItemCreated event is firing every time post back is occurring. Please do your databinding only first time when page loads. You can use IsPostBack property to check if it is a postback or fresh loading of page.
Page_Load(....){
if(!IsPostBack){
LoadData();
}
}
If you do not want to use postback on button click, please use ajax and page methods. You can get more information here: Using jQuery AJAX to directly call page methods.

Categories