when change make from javascript it doesnot get in codebehind(server side)

Last post 07-07-2009 11:16 AM by mudassarkhan. 5 replies.

Sort Posts:

  • when change make from javascript it doesnot get in codebehind(server side)

    07-07-2009, 9:48 AM

    Hello,

    I have one <tr style="display:block"> (htmltable row) which has style display:block in aspx page

    Now onclick of one button i make that tr style to display:none from javascript

    also from browser that row disappears,

    however when i try to get display property in codebehind when postback, still it gives

    display:block

    I also check the page source from browser that any change i make from javascript doesnot affect in page source.


    How to solve this problem?

    Thanks.

    VISHAL PAREKH
  • Re: when change make from javascript it doesnot get in codebehind(server side)

    07-07-2009, 10:14 AM
    • All-Star
      59,893 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,551

     Yes javascript changes are not persisted when page is reloaded

    in that case simply add runat="server" to tr and give an ID

    <tr id = "myrow" runat = "server">

     

    Thus not you can access it in code behind

    myrow.Attributes.Add("style", "display:block")

  • Re: when change make from javascript it doesnot get in codebehind(server side)

    07-07-2009, 10:46 AM

    Thanks mudassarkhan for reply,

    but i want that user can hide some tr from clientside only and i also want that

    in codebehind when postback occurs i get that value as hide only.

    i.e. when one <tr id="testtr" runat="server" style="display:block"> when page loads first time

                                  user click button and make them display:none by javascript

    now he submit the page, now in codebehind i want the display style of testtr (html row) as none and not block


    VISHAL PAREKH
  • Re: when change make from javascript it doesnot get in codebehind(server side)

    07-07-2009, 10:57 AM
    • All-Star
      59,893 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,551

     You will need hidden field for that

    Add a hidden field

    <input id="hid" name = "hid" type="hidden" value = "block" />

     

    Then on button click store the value  none in hidden field using javascript

    now in codebehind do

    testtr.Attributes.Add("style", "display:" + Request.Form["hid"]);

     

    It will preserve the changes

     

  • Re: when change make from javascript it doesnot get in codebehind(server side)

    07-07-2009, 11:07 AM

    Thanks mudassarkhan

    I have many htmlrows,span tags, htmlcoloumns that hides from clientside (by javascript),

    so to follow your suggested solution i have to take as many hidden variables as controls which affect from clientside.

    Is there any short way or alternate soltion to solve this problem?

    Again Thanks for helping me.

    VISHAL PAREKH
  • Re: when change make from javascript it doesnot get in codebehind(server side)

    07-07-2009, 11:16 AM
    Answer
    • All-Star
      59,893 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 5:28 AM
    • Mumbai, India
    • Posts 10,551

     No there is no shorter way JavaScript changes will always be discareded since each time your page is recereated only way

    is to provide some value to Server as I did and do it Server side

    Another solution is use updatepanel since it partially refreshes the page thus the HTML outside updatepanel will never be refreshed

Page 1 of 1 (6 items)