Sharepoint 2010 Custom Visual Webpart button click event firing on page refresh

I have developed a Visual Webpart to create a list in SP using vs2010 and  the button click event I have written the list create method. If I click the button list is created successfully.  And I refresh the page again list is creating(Again button
click event is triggering).please help me to solve the issue.
 protected void Button1_Click(object sender,
EventArgs e)
            SPWeb web
= SPContext.Current.Web;
            //SPList list=web.Lists["Auto"];
            SPList list
= web.Lists[DropDownList2.SelectedItem.Text];
            if
(string.IsNullOrEmpty(TextBox1.Text)
|| string.IsNullOrEmpty(DropDownList1.Text))
Label4.Text =
"Fields Are Empty";
            else
if (DropDownList1.SelectedItem.Text
== "Single line of Text")
                list.Fields.Add(TextBox1.Text,
SPFieldType.Text,
true);
SPView viewname = list.Views["All Items"];
                viewname.ViewFields.Add(TextBox1.Text);
//viewname.Update();
                list.Update();
Label4.Text =
"Field Created Successfully";
TextBox1.Text =
string.Empty;
// Label4.Text = string.Empty;

Hi,
This is because the request is sent to the server when you refresh the page.
A workaround for this is that we can “provide a refresh link that redirects to the same page (or if you have some action causing the refresh programmatically, you could just
redirect to the page after that, with Response.Redirect)
so that page is requested by the browser (with GET method, default with hyperlinks)”.
More information:
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/45648b39-1229-405c-ac9e-60eb82905982/click-event-getting-fired-on-page-refresh
Or we can use the Session to save a value which used as a flag for us to check whether it is a page refresh and perform accordingly.
http://www.codeproject.com/Articles/28099/Refresh-Page-Issue-in-ASP-Net
http://www.codeproject.com/Articles/10240/Detecting-Page-Refresh
Thanks
Patrick Liang
TechNet Community Support

Similar Messages

  • How do you fire a button click event on apex page from fancybox iframe that was created by page

    I am trying to fire off the button click event from fancybox iframe. The apex page has a button that launches a fancybox iframe which is loaded with an APEX form. On close of that fancy box, I am trying to fire a click event on the parent page which will refresh a div with html that is created with plsql. The button on the page works as expected when clicked from the page. It will show a debug alert message to prove it was called and then load the div with the correct data. I am unable to fire off this button click from the fancybox iframe when it closes.
    A couple of points:
    I using Plug-in: Execute PL/SQL Code and Return Content ("PLUGIN_MULEDEV.SERVER_REGION_REFRESH") to place the create fancybox statement. It is used to populate a div using plsql.
    The name of the button on the main page is P2020_REFRESH_SECTION_BUILDER_BTN.
    The click dynamic action on the button is calling the plugin to replace the html in the div.
    The data in the form in the fancybox is being saved to the database. On close of the fancybox box I want to refresh the div so the new record is included in the div html.
    Can anyone help. Here is the fancybox code:
      function customProcessOnReadyState4(){
        for (var i=0;i<11;i++){
          $( "#tabs"+i ).tabs();
          $("#createNewExerciseLink"+i).fancybox({
              ''width''         : ''60%'',
              ''height''        : ''70%'',
              ''autoScale''     : true,
              ''transitionIn''  : 200,
              ''transitionOut'' : 200,
              ''type''          : ''iframe'',
              ''onClosed''         : function() {
                                         window.parent.$(''#P2020_REFRESH_SECTION_BUILDER_BTN'').click();
    Here are the dynamic actions assigned to the button:
    5 - Execute JavaScript Code
    alert("Starting refresh");
    10 - Execute PL/SQL Code and Return Content [Plug-in]
    begin
      SCTUI.create_sct_tabs2(:P2020_CREATE_SECTION_LOV, '1');
    end;

    user setActionListener...
    <af:setActionListener from="#{bindings.XXX.inputValue" to="#{backingbean.variable}"
                  <af:inputText value="#{bindings.Email.inputValue}"
                                label="#{bindings.Email.hints.label}"
                                binding="#{backingBeanScope.backing_ShuttlePage.it2}"
                                id="it2">
                    <f:validator binding="#{bindings.Email.validator}"/>
                  </af:inputText>
                  <af:commandButton text="commandButton 2"
                                    binding="#{backingBeanScope.backing_ShuttlePage.cb2}"
                                    id="cb2" action="passing">
                    <af:setActionListener from="#{bindings.Email.inputValue}"
                                          to="#{processScope.detail}"/>
                  </af:commandButton>next jsf page:
                <af:outputText value="#{processScope.detail}"
                               binding="#{backingBeanScope.backing_ProcessScope.ot1}"
                               id="ot1"/>setPropertyListener also should work
    <af:setPropertyListener from="#{bindings.Email.inputValue}" to="#{processScope.detail}" type="action"/>

  • How to generate barcode on button click event in PDF using adobe livecycle?

    I already created form in PDF file which is validate completely .But , I required generate a barcode of all field of form using custom script on button click event.
    Please give me right way for doing it .
    Thanks in Advance,
    Jaydeep Solanki.

    Hi vijay,
    What project are you doing? Is it Asp.Net project? If so, you'll need to post it in the dedicated ASP.Net Forum
    http://forums.asp.net  for more efficient responses, where you can contact ASP.NET experts.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • HOW TO CALL APPROVAL WORK FLOW ON BUTTON CLICK EVENT OF VISUAL WEB PART?

    Hiall,
    I created an OOB an approval work flow I want to start that approval work flow through visual web  part button click event
    In work flow Settings I selected to manually start .Is this possible ? if possible please guide me how to do this
    Thanking you,
    Arun  kumar

    Hi,
    If you have an instance of SPListItem, and know the workflow association name, you can start it. First you need to find workflow assocation instance and tell SPSite.SPWorkflowManager to start your workflow.
    See this for more information:
    http://blog.mmasood.com/2012/06/programatically-start-workflow.html
    Please remember to up-vote or mark the reply as answer if you find it helpful.

  • Call External Javascript file in Custom Visual WebPart

     Hi..
     How to call external javascript file in Custom Visual WebPart in sharepoint 2010
    Ravindranath

    Hello,
    Download that script and save in layout folder or within a site. Then use below script tag in webpart:
    <SharePoint:ScriptLink ID="ScriptLink2" Name="location/jquery-1.5.min.js" runat="server" OnDemand="false" Localizable="false" />
    http://stackoverflow.com/questions/5068663/how-to-call-an-external-javascript-file-from-a-webpart
    http://stackoverflow.com/questions/5243821/external-javascript-file-in-sharepoint-web-part
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to call elem. Search help on Button click event in WD appilcation

    Hello All,
    i have requirement to call elem. search help on button click event in WD application. currently i am calling FM  F4IF_START_VALUE_REQUEST but getting the short dump as below,
    The following error text was processed in the system X31 : Screen output without connection to user.
    The error occurred on the application server saps_X31_31 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    SYSTEM-EXIT of program SAPLSDH4
    Function: F4_PRESEL_WITH_TABSTRIP of program SAPLSDH4
    Form: F4PROZ_STEP_PRESEL of program SAPLSDSD
    Function: DD_SHLP_SINGLE_STEP of program SAPLSDSD
    Form: F4PROZ_LOOP of program SAPLSDSD
    Form: F4PROZ of program SAPLSDSD
    Function: F4IF_START_VALUE_REQUEST of program SAPLSDHI
    Method: ONACTIONSEARCH_CUSTOMER of program /1BCWDY/50TU5ZEXF3K0IWCWE153==CP
    Method: IF_WDR_VIEW_DELEGATE~WD_INVOKE_EVENT_HANDLER of program /1BCWDY/50TU5ZEXF3K0IWCWE153==CP
    Method: INVOKE_EVENTHANDLER of program CL_WDR_DELEGATING_VIEW========CP
    is there any way to achieve the required behaviour.
    please let me know.
    Regards,
    Chandra

    Hi Friends,
    I have the similar kind of requirement. Upon click on a Button on screen i need to call a search help, and collect one or more selected material numbers.
    The search help is working fine and i am getting the entries with the following code.
    The problem is i am finding extra popup on screen.
    CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'
    EXPORTING
    tabname         =  space
    fieldname       =  space
    SEARCHHELP      =  'MAT1'
    MULTIPLE_CHOICE =  'X'
    STEPL           =  0
    value           = 'MATNR'
    *dynpprog        =  progname
    *dynpnr          =  dynnum
    *dynprofield     = 'CARRIER'
    CALLBACK_PROGRAM          = 'ZTEST_1_PRA'
    CALLBACK_FORM             = 'F4CALLBACK'
    TABLES
    RETURN_TAB                = RETURN_TAB
    EXCEPTIONS
    FIELD_NOT_FOUND           = 1
    NO_HELP_FOR_FIELD         = 2
    INCONSISTENT_HELP         = 3
    NO_VALUES_FOUND           = 4
    OTHERS                    = 5.

  • Capturing navigation button click event

    Hi,
    Is it possible to capture the navigation button click events on a system form?For example when the goods receipt form is open and i click on navigation button on the tool bar.
    Can help with some sample codes?
    Thanks.
    Satish.

    Hi,
    Here you´ve got an example from the UI API help file.
    Private Sub SBO_Application_MenuEvent(pVal As SAPbouiCOM.IMenuEvent, BubbleEvent As Boolean)
        If pVal.MenuUID = "1288" Or _
            pVal.MenuUID = "1289" Or _
            pVal.MenuUID = "1290" Or _
            pVal.MenuUID = "1291" Then
          If pVal.BeforeAction = False Then
              Select Case pVal.MenuUID
                '// Under the If clause, check each item if it was clicked
                Case "1288"
                    oRecordSet.MoveNext
                    '// If reached EOF show last
                    If oRecordSet.EOF = True Then
                        oRecordSet.MoveLast
                    End If
                Case ...
                End Select
            End If
        End If
    End Sub
    To know the current form, you can use the ActiveForm property.
    Regards,
    Ibai Peñ

  • FileDialog.SAVE: trap the "Save" button click event

    Hello All
    Can anyone help me with FileDialog.SAVE, as to how we could trap the Save button click event? Is it possible to actually trap that particular event, rather than just checking for FileDialog.getFile() == null -> which indicates that "Cancel" button was selected.
    Any help would be highly appreciated
    Regards
    Naushin

    You can not do this, because FileDialog uses native dialog and all
    buttons on it are native (there are no java-components for them).
    Thus checking FileDialof.getFile() for null is only way to figure out
    whether user choose some file or not.

  • Error with No Message on Button Click Event

    Hi,
    I am getting a framework error on button click event.
    I have a page in which shuttle component is there,on click of the commit button the page traversed to main jsp page there i am getting error like ERROR and only '-'.
    In application module java file i have written the code for the shuttle component which creates the new row and set the values.

    Hi Frank. Thanks for the answer. Kindly check the code for shuttle component below. This is written in the Application Module (..ServicesImpl.java)
    public void multipleShuttle(List productIds,String reqRefNumber,Date orderDate,String hoSectionCd)
    System.out.println("Its entering into the test method");
    System.out.println("Inside updateSkillsForCurrentStaff method");
    System.out.println("reqRefNumber:"+reqRefNumber);
    System.out.println("orderDate:"+orderDate);
    System.out.println("hoSectionCd:"+hoSectionCd);
    if (productIds != null && productIds.size() > 0)
    List<Number> copyOfProductIds = (List<Number>)Utils.cloneList(productIds);
    //List copyOfProductIdsNames=Utils.cloneList(productIds);
    System.out.println("list values "+copyOfProductIds);;
    //System.out.println("list values "+copyOfProductIdsNames);;
    ViewObject skills = getMsMsOrderHdrUO2();
    RowSetIterator rsi = skills.createRowSetIterator(null);
    // remove any rows for the current user that aren't in the list of product keys
    while (rsi.hasNext())
    Row r = rsi.next();
    Number productId = (Number)r.getAttribute("MsDepotCd");
    System.out.println("depot from row setter "+productId);
    // if the existing row is in the list, we're ok, so remove from list.
    if (copyOfProductIds.contains(productId))
    copyOfProductIds.remove(productId);
    // if the existing row is in not list, remove it.
    else {
    r.remove();
    rsi.closeRowSetIterator();
    // at this point, we need to add new rows for the keys that are left
    for (Number productIdToAdd: copyOfProductIds)
    Row newRow = skills.createRow();
    skills.insertRow(newRow);
    try
    System.out.println("productIdToAdd"+productIdToAdd);
    System.out.println("inside attributes setter try method");
    //AS PER THE NEW REQUIREMENT ORDER STAUTS WIL BE 'DRAFT' AND ON APPROVAL BY JGM THEN IT WILL BE 'APPROVED'
    newRow.setAttribute("OrderStatus","DRAFT");
    System.out.println("Depot Code set is"+newRow.getAttribute("DepotCd"));
    if(productIdToAdd.equals("0"))
    System.out.println("inside the HO method to set section");
    newRow.setAttribute("HoSections",hoSectionCd);
    System.out.println("After setting the values");
    catch(Exception e)
    System.out.println("Exception Caught"+e);
    getDBTransaction().commit();
    orderDetailInsertProcedure(reqRefNumber);
    }

  • Button Click Event WebPart Button Sys.Webforms.PageRequestManagerServerErrorException:

    Hi,
    I have a SharePoint 2010 visual WebPart, which has ASP.NET Multiview control. When deployed, this control works fine on my local server and it even works fine in the Development server; however, when deployed on to the production server, it stops working.
    I am not able to change Views on the production server, when I try to debug the WebPart in IE Developer Tool (Using IE 11), I get this error that says “Sys.WebForms.PageRequestManagerServerErrorException: An unexpected error has occurred.” in the ScriptResource.axd
    file.
    Even the Button click is not working, getting the same error in the Button Click.
    Can someone help me with this?
    Regards, Vikram

    Hi Hemendra,
    Thanks for your help, but the problem is solved now. turns out the issue was not with the control but the page itself.
    I had copy pasted the pages from my local server to the production server instead of exporting and importing it.
    Once i created pages in the production server, the issue was solved.
    Regards, Vikram

  • Cannot "Add new Item" in my SharePoint 2010 custom lists

    Hi guys,
                All these days it was working fine and all of sudden now when i click on "Add new item" in the the custom lists which i have created in my SharePoint 2010 and fill in the fields and click "save",
    I am getting an exception...:( 
    Please HELP!!!
    Neo Alpha

    One more thread for the same issue
    http://social.msdn.microsoft.com/Forums/en-US/51f37f3b-18a3-4d6b-b90f-2a4240306bf8/when-update-a-folders-property-it-throw-a-comexception-0x81020089
    hope this will help you
    Senthilrajan Kaliyaperumal

  • Using style sheets in a button click event

    hi. doing a project and extending the WoodStocks application. so need to google and find how to add keyboard short cuts to the data grid, the combo box, how to manually add the read only and edit columns and to do error handling for the save button. once
    i do this, then need to have two buttons. two different styles sheets, and using xml and xsl. so, do i just then do the xml and the xsl style sheet headers in a cutton click event. have gone through the learning from http://www.w3schools.com, and done the
    xml and the xsl tutorials. and so. just asking for your feedback, tips and tricks. and now, looking to have two style sheets, one for a visual user and one for a blind user. what aspects should i have in each style sheet. looking for feedback, advice. thanks.
    marvin.
    http://startrekcafe.stevesdomain.net http://groups.yahoo.com/groups/JawsOz

    hi. but i need to do this in c #, so it is relevant to c#
    http://startrekcafe.stevesdomain.net http://groups.yahoo.com/groups/JawsOz

  • Sharepoint 2010, after restore, webpart only can viewd by authenticated users in the public page.

    Hi, I restore a Site from one server to other which have a different domain.
    I installed the wsp files, I published the page, I check for the site pages and everything is ok but, when I visit the page as normal
    user from internet, I get the next error when I visited the pages with webparts.
    When I visit the page with an authenticated user, that show me the webpart normaly.
    I try to check for permissions in the page, I click page permissions
    or library permissions and shows the next:
    Shows me the same error.
    Any ideas?
    Thanks a lot!!

    Hi,
    As I understand, after you restored the site from one server to other server you encountered the error.
    1. From the error you provided, it seems that it cannot find relative files, it is possible that you did not restore the site fully. You can restore the site again. 
    2. You can check the ULS log with the correlation ID, and get the details of the errors. You can fix the problems according to the details of the errors. 
    The case below is about there are several ways to backup and restore site in SharePoint 2010, you can refer to the case.
    http://sharepoint.stackexchange.com/questions/34639/problem-restoring-sharepoint-from-backup 
    Best regards,
    Sara Fan
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Show a custom component on button click in a view stack`

    Hello folks
    I have a view stack in which i have some custom components.
    Now there is one custom component in which there is one button. On the button click, i want to show another custom component but i dont know how to do it. Should i write the inline mxml click event in custom component?? If yes then how??
    Currently i am doing it as
    click="{customcomponent}"

    As you know, ViewStack  has containers, lilke VBox for its views.
    Assuming one of your views VBox has an id of myVBox, and that VBox has the Button that when clicked will display the component, just have the component in the view already, but you can make it invisible with visible=false and includeInLayout=false, and then upon button click set those two variables to true.
    You will probably want a show handler for the view VBox to make those properties false each time that view is displayed.
    Here is some simple sample code.
    If this post answers your question or helps, please mark it as such.
    ---------- MySimpleComponent.mxml ----------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
      width="100%" height="100%" horizontalAlign="center">
      <mx:Label text="My Custom Component"/>
    </mx:VBox>
    ---------- MainApp.mxml  ----------
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      xmlns:comp="*" horizontalAlign="center" verticalAlign="middle">
      <mx:Script>
        <![CDATA[
        ]]>
      </mx:Script>
      <mx:LinkBar dataProvider="{vs}"/>
      <mx:ViewStack id="vs" width="100%" height="100%">
        <mx:VBox label="view1" width="100%" height="100%"
          horizontalAlign="center">
          <mx:Label text="View One"/>
        </mx:VBox>
        <mx:VBox label="view2"  width="100%" height="100%"
          show="myComp.visible=false;myComp.includeInLayout=true;"
          horizontalAlign="center">
          <mx:Label text="View Two"/>
          <mx:Button label="Make myComp Visible" click="myComp.visible=true;myComp.includeInLayout=true;"/>
          <comp:MySimpleComponent id="myComp" visible="false" includeInLayout="false"/>
        </mx:VBox>
      </mx:ViewStack>
    </mx:Application>

  • Sharepoint 2010 custom search for subsites

    Sharepoint 2010
    Hello, i have main site and about 30 subsites. And on each subsite about 30 document librarys.
    I created basic search center custom site with name "Search". I also created custom scope. So when i search on my main site, anything is fine and when i go to subsite document library my scope is changed to this site:document librarys name. Then
    i pu something in search line and click search. On my custom search page i can see, that all links are from correct subsite and correct document library, but my scope shows "This Site:Search". So when i put something else in my search line and click
    search, i dont get any results, because it searches only on search page. Even when i click on scope dropdown, there is no choice, only "This Site:Search". 
    Is there any solution to create a search scope, that would take the parameters from the document librarys URL from wich i am searching for and put it in the scope.
    P.S.
    Default search OSSSearchResults.aspx works fine, but i nead to change xsl code.
    I tried to put scope dropdown to "show and default to url parametr", but nothing is changed.

    Hi Dmitri,
    If you want to search on a library, you can go to the library, then search using the Search Box at the top of the page. When you search, it will go to the OSSSearchResults.aspx page, and on the page, you will find there are two search scope, one is the library,
    another is the site. If you want to search on another library, you can go to another library, then search.
    Or, you can create a custom search scope pointed to the library, and add the search scope into the Search Dropdown display group.
    More infoemation, please refer to the link:
    http://www.bentedder.com/create-a-search-scope-for-a-sharepoint-2010-list-or-library/
    http://www.youtube.com/watch?v=9rt4hrMKs3o
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

Maybe you are looking for

  • Testing for IS NOT NULL with left join tables

    Dear Experts, The query is showing the NULL rows in the query below.... Any ideas, advice please? tx, sandra This is the sql inspector: SELECT O100321.FULL_NAME_LFMI, O100321.ID, O100404.ID, O100321.ID_SOURCE , O100404.NAME, O100321.PERSON_UID, O1004

  • Hard drive and brightness increase/decrease noise

    Hi, It's been a couple of months since am I hearing a lot of noise from my hard drive. Supposedly I am browsing safari and the next moment, I open a finder window, it feels like the HD rises from the dead with that noise and it takes about 3-5 second

  • T-60 - Error: Blue Tooth Stack

    T-60 2623D6U with XP Professional. I was recently hit with the trojan from ... well wherever trojans come from other than USC.  Anyway, it forced me to reformat and reload.  Since I bought a few new programs and updated a few others there was a bit o

  • Help Help disk mode crisis!

    help recently after trying to restore my ipod to factory settings, I then tried to update all my songs on itunes and it stopped halfway and my pc crashed. Then trying to update the songs again i fund my ipod was in disk mode after trying to reset it

  • STW00226 Error on Installation

    Hi: I'm having an issue installing BOE on Windows 2003 R2 64-bit.  What we have done so far: created a database on SQL 2005 via 32-bit drivers for the object repository (CMS database) and have successfully tested the connection from the Windows box t