By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

Javascript Server-side Action Questions..

P: n/a
Hi everybody,

Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1. <td id="mam" height="180">
  2. <iframe id="NewsBody_rich" src="includes/MsgBody.htm"
  3. width="100%" height="100%"
  4. onblur="fillTxt()" style="font-family:
  5. Arial"></iframe>
  6. </td>
  7.  
  8. //Javascript function to be executed
  9. function setTxt(szText)
  10. {
  11. var State = new Object()
  12. var aa;
  13. NewsBody_rich.document.body.innerHTML = szText;
  14. }
  15.  
Question 2:
Expand|Select|Wrap|Line Numbers
  1. UserControl mentioned
  2. <%@ Control Language="C#" AutoEventWireup="true"
  3. CodeFile="AlbumDetailList.ascx.cs" Inherits="usercontrols_AlbumDetailList" %>
  4. <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  5. <table id="tblMain" width="824" border="0">
  6. ....
  7. <tr>
  8. <td>
  9. <asp:Panel ID="pnlPhotos" runat="server" Height="100px"
  10. Width="824px">
  11. </asp:Panel>
  12. </td>
  13. </tr>
  14. ...
  15. </table>
  16. </asp:Panel>
  17.  
  18. Inside MasterPage:
  19.  
  20. <script language="javascript" type="text/javascript">
  21. .....
  22. function ConfirmDelete(szText)
  23. {
  24. var confirmed = confirm("Are you sure you want to delete the " +
  25. szText + "?");
  26.  
  27. if(confirmed)
  28. return true;
  29. else
  30. return false;
  31. }
  32. .....
  33. </script>
  34.  
  35. //Add attributes to delete buttons
  36. private void InitializeButtonAttributes()
  37. {
  38. btnDelete1.Attributes.Add("onclick", "javascript:return
  39. ConfirmDelete('Image/s')");
  40. btnDelete2.Attributes.Add("onclick", "javascript:return
  41. ConfirmDelete('Image/s')");
  42. }
  43.  
  44. I need to execute this method:
  45. //Remove Checked in CheckBox
  46. private void ReInitializeCheckbox()
  47. {
  48. foreach (Control ctrl in myPanel.Controls)
  49. {
  50. ....
  51. CheckBox chkPhoto = (CheckBox)ctrl.FindControl(ctrl.ID);
  52.  
  53. if (chkPhoto.Checked)
  54. chkPhoto.Checked = false;
  55. ...
  56. }
  57. }
  58.  
  59. // As suggested in another forum, I tried this but when cancel is click,
  60. it executed
  61. //the GetSelectedPhotosForDeletion() method
  62. function ConfirmDelete(szText)
  63. {
  64. var confirmed = confirm("Are you sure you want to delete the " +
  65. szText + "?");
  66.  
  67. if(confirmed)
  68. return true;
  69. else
  70. {
  71.  
  72. var allInputs = Form1.getElementsByTagName('INPUT'); //check all
  73. input boxes
  74.  
  75. for ( var i=0; i<allInputs.length; i++ )
  76. {
  77. if ( allInputs.type == 'checkbox'
  78. )
  79. {
  80. if ( allInputs.checked)
  81. allInputs.checked =
  82. false;
  83. }
  84. }
  85. //do the same for 'select' controls and
  86. radio buttons
  87. return false;
  88. }
  89. }
  90.  
  91.  
  92. //This gets executed
  93. protected void btnDelete_Click(object sender, EventArgs e)
  94. {
  95. GetSelectedPhotosForDeletion();//even clicking cancel in
  96. confirm this gets executed..
  97. }
  98.  
  99.  
Thanks in advanced..

den2005

--
MCP Year 2005, Philippines
Oct 6 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
>
Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?
What ever asp.net control post back to your server even handler add
the following code

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName()</script>");

when page post back this method will be called on page load, if needed , you
can also pass value to your javascripr function from server side.

like below

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName('param1',
'param2')</script>");
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?
since you are return true or false in your confirmation , your delete button
event handler will be called back upon true,
there you can write your checkbox selection logic.
"den 2005" <de*****@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Hi everybody,

Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1.                <td id="mam" height="180">
  2.                    <iframe id="NewsBody_rich" src="includes/MsgBody.htm"
  3. width="100%" height="100%"
  4.                        onblur="fillTxt()" style="font-family:
  5. Arial"></iframe>
  6.                </td>
  7. //Javascript function to be executed
  8.                function setTxt(szText)
  9. {
  10.   var State = new Object()
  11.   var aa;
  12.   NewsBody_rich.document.body.innerHTML = szText;
  13. }
  14.  

Question 2:
Expand|Select|Wrap|Line Numbers
  1. UserControl mentioned
  2. <%@ Control Language="C#" AutoEventWireup="true"
  3. CodeFile="AlbumDetailList.ascx.cs" Inherits="usercontrols_AlbumDetailList"
  4. %>
  5. <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  6.    <table id="tblMain" width="824" border="0">
  7.        ....
  8.       <tr>
  9.            <td>
  10.                <asp:Panel ID="pnlPhotos" runat="server" Height="100px"
  11. Width="824px">
  12.                </asp:Panel>
  13.            </td>
  14.        </tr>
  15.       ...
  16.   </table>
  17. </asp:Panel>
  18. Inside MasterPage:
  19. <script language="javascript" type="text/javascript">
  20. ....
  21.   function ConfirmDelete(szText)
  22.    {
  23.        var confirmed = confirm("Are you sure you want to delete the " +
  24. szText + "?");
  25.        if(confirmed)
  26.            return true;
  27.        else
  28.            return false;
  29.    }
  30. ....
  31. </script>
  32. //Add attributes to delete buttons
  33.    private void InitializeButtonAttributes()
  34.    {
  35.        btnDelete1.Attributes.Add("onclick", "javascript:return
  36. ConfirmDelete('Image/s')");
  37.        btnDelete2.Attributes.Add("onclick", "javascript:return
  38. ConfirmDelete('Image/s')");
  39.    }
  40. I need to execute this method:
  41. //Remove Checked in CheckBox
  42.    private void ReInitializeCheckbox()
  43.    {
  44.        foreach (Control ctrl in myPanel.Controls)
  45.        {
  46.            ....
  47.                CheckBox chkPhoto = (CheckBox)ctrl.FindControl(ctrl.ID);
  48.                if (chkPhoto.Checked)
  49.                    chkPhoto.Checked = false;
  50.            ...
  51.        }
  52.    }
  53.  // As suggested in another forum, I tried this but when cancel is click,
  54. it executed
  55.  //the GetSelectedPhotosForDeletion() method
  56.  function ConfirmDelete(szText)
  57.    {
  58.        var confirmed = confirm("Are you sure you want to delete the " +
  59. szText + "?");
  60.        if(confirmed)
  61.            return true;
  62.        else
  63.        {
  64.         var allInputs = Form1.getElementsByTagName('INPUT'); //check all
  65. input boxes
  66.     for ( var i=0; i<allInputs.length; i++ )
  67.                 {
  68.                                           if ( allInputs.type ==
  69. 'checkbox'
  70. )
  71.                                          {
  72.                                                if ( allInputs.checked)
  73.                                                      allInputs.checked =
  74. false;
  75.                                          }
  76.                                    }
  77.                                    //do the same for 'select' controls and
  78. radio buttons
  79.                        return false;
  80.        }
  81.    }
  82.  //This gets executed
  83.  protected void btnDelete_Click(object sender, EventArgs e)
  84.    {
  85.              GetSelectedPhotosForDeletion();//even clicking cancel in
  86. confirm this gets executed..
  87.    }
  88.  

Thanks in advanced..

den2005

--
MCP Year 2005, Philippines

Oct 6 '06 #2

P: n/a
Thanks Baski for replying...

I tried what you suggested in question 1, it's not working, what is wrong
with this?

Inside Parent user control:

RichTextEditor1.SetEditorContent(dr["Contents"].ToString());

Inside RichTextEditor user control class:

public void SetEditorContent(string contents)
{
this.EditorContent = contents;
//Page.ClientScript.RegisterClientScriptBlock(this.G etType(),
"RunFunction", "setTxt('" + contents + "')");
Page.RegisterStartupScript("StartupScript", "setTxt('" + contents +
"')");
}

The second question has been resolved in another post on this same forum.
--
MCP Year 2005, Philippines
"Baski" wrote:

Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?

What ever asp.net control post back to your server even handler add
the following code

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName()</script>");

when page post back this method will be called on page load, if needed , you
can also pass value to your javascripr function from server side.

like below

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName('param1',
'param2')</script>");
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

since you are return true or false in your confirmation , your delete button
event handler will be called back upon true,
there you can write your checkbox selection logic.
"den 2005" <de*****@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Hi everybody,

Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1.                 <td id="mam" height="180">
  2.                     <iframe id="NewsBody_rich" src="includes/MsgBody.htm"
  3.  width="100%" height="100%"
  4.                         onblur="fillTxt()" style="font-family:
  5.  Arial"></iframe>
  6.                 </td>
  7.  
  8.  //Javascript function to be executed
  9.                 function setTxt(szText)
  10.  {
  11.    var State = new Object()
  12.    var aa;
  13.    NewsBody_rich.document.body.innerHTML = szText;
  14.  }
  15.  
Question 2:
Expand|Select|Wrap|Line Numbers
  1.  UserControl mentioned
  2.  <%@ Control Language="C#" AutoEventWireup="true"
  3.  CodeFile="AlbumDetailList.ascx.cs" Inherits="usercontrols_AlbumDetailList"
  4.  %>
  5.  <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  6.     <table id="tblMain" width="824" border="0">
  7.         ....
  8.        <tr>
  9.             <td>
  10.                 <asp:Panel ID="pnlPhotos" runat="server" Height="100px"
  11.  Width="824px">
  12.                 </asp:Panel>
  13.             </td>
  14.         </tr>
  15.        ...
  16.    </table>
  17.  </asp:Panel>
  18.  
  19.  Inside MasterPage:
  20.  
  21.  <script language="javascript" type="text/javascript">
  22.  ....
  23.    function ConfirmDelete(szText)
  24.     {
  25.         var confirmed = confirm("Are you sure you want to delete the " +
  26.  szText + "?");
  27.  
  28.         if(confirmed)
  29.             return true;
  30.         else
  31.             return false;
  32.     }
  33.  ....
  34.  </script>
  35.  
  36.  //Add attributes to delete buttons
  37.     private void InitializeButtonAttributes()
  38.     {
  39.         btnDelete1.Attributes.Add("onclick", "javascript:return
  40.  ConfirmDelete('Image/s')");
  41.         btnDelete2.Attributes.Add("onclick", "javascript:return
  42.  ConfirmDelete('Image/s')");
  43.     }
  44.  
  45.  I need to execute this method:
  46.  //Remove Checked in CheckBox
  47.     private void ReInitializeCheckbox()
  48.     {
  49.         foreach (Control ctrl in myPanel.Controls)
  50.         {
  51.             ....
  52.                 CheckBox chkPhoto = (CheckBox)ctrl.FindControl(ctrl.ID);
  53.  
  54.                 if (chkPhoto.Checked)
  55.                     chkPhoto.Checked = false;
  56.             ...
  57.         }
  58.     }
  59.  
  60.   // As suggested in another forum, I tried this but when cancel is click,
  61.  it executed
  62.   //the GetSelectedPhotosForDeletion() method
  63.   function ConfirmDelete(szText)
  64.     {
  65.         var confirmed = confirm("Are you sure you want to delete the " +
  66.  szText + "?");
  67.  
  68.         if(confirmed)
  69.             return true;
  70.         else
  71.         {
  72.  
  73.          var allInputs = Form1.getElementsByTagName('INPUT'); //check all
  74.  input boxes
  75.  
  76.      for ( var i=0; i<allInputs.length; i++ )
  77.                  {
  78.                                            if ( allInputs.type ==
  79.  'checkbox'
  80.  )
  81.                                           {
  82.                                                 if ( allInputs.checked)
  83.                                                       allInputs.checked =
  84.  false;
  85.                                           }
  86.                                     }
  87.                                     //do the same for 'select' controls and
  88.  radio buttons
  89.                         return false;
  90.         }
  91.     }
  92.  
  93.  
  94.   //This gets executed
  95.   protected void btnDelete_Click(object sender, EventArgs e)
  96.     {
  97.               GetSelectedPhotosForDeletion();//even clicking cancel in
  98.  confirm this gets executed..
  99.     }
  100.  
  101.  
Thanks in advanced..

den2005

--
MCP Year 2005, Philippines


Oct 9 '06 #3

P: n/a
Baski,

I try to follow what you suggested as answer in question # 1, but it's
not working, Am I missing something or not doing it right?

Inside Parent User Control:

RichTextEditor1.SetEditorContent(dr["Contents"].ToString());

Inside RichTextEditor user control:

public void SetEditorContent(string contents)
{
this.EditorContent = contents;
//Page.ClientScript.RegisterClientScriptBlock(this.G etType(),

// "RunFunction", "setTxt('" + contents + "')");
Page.RegisterStartupScript("StartupScript", "setTxt('" + contents +
"')");
}

The second question has been answered in another post on this same forum.

Dennis
--
MCP Year 2005, Philippines
"Baski" wrote:

Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?

What ever asp.net control post back to your server even handler add
the following code

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName()</script>");

when page post back this method will be called on page load, if needed , you
can also pass value to your javascripr function from server side.

like below

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName('param1',
'param2')</script>");
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

since you are return true or false in your confirmation , your delete button
event handler will be called back upon true,
there you can write your checkbox selection logic.
"den 2005" <de*****@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Hi everybody,

Question 1: How do you set the values from server-side to a client-side
control or how do you execute a javascript function without a button click
event?
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1.                 <td id="mam" height="180">
  2.                     <iframe id="NewsBody_rich" src="includes/MsgBody.htm"
  3.  width="100%" height="100%"
  4.                         onblur="fillTxt()" style="font-family:
  5.  Arial"></iframe>
  6.                 </td>
  7.  
  8.  //Javascript function to be executed
  9.                 function setTxt(szText)
  10.  {
  11.    var State = new Object()
  12.    var aa;
  13.    NewsBody_rich.document.body.innerHTML = szText;
  14.  }
  15.  
Question 2:
Expand|Select|Wrap|Line Numbers
  1.  UserControl mentioned
  2.  <%@ Control Language="C#" AutoEventWireup="true"
  3.  CodeFile="AlbumDetailList.ascx.cs" Inherits="usercontrols_AlbumDetailList"
  4.  %>
  5.  <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  6.     <table id="tblMain" width="824" border="0">
  7.         ....
  8.        <tr>
  9.             <td>
  10.                 <asp:Panel ID="pnlPhotos" runat="server" Height="100px"
  11.  Width="824px">
  12.                 </asp:Panel>
  13.             </td>
  14.         </tr>
  15.        ...
  16.    </table>
  17.  </asp:Panel>
  18.  
  19.  Inside MasterPage:
  20.  
  21.  <script language="javascript" type="text/javascript">
  22.  ....
  23.    function ConfirmDelete(szText)
  24.     {
  25.         var confirmed = confirm("Are you sure you want to delete the " +
  26.  szText + "?");
  27.  
  28.         if(confirmed)
  29.             return true;
  30.         else
  31.             return false;
  32.     }
  33.  ....
  34.  </script>
  35.  
  36.  //Add attributes to delete buttons
  37.     private void InitializeButtonAttributes()
  38.     {
  39.         btnDelete1.Attributes.Add("onclick", "javascript:return
  40.  ConfirmDelete('Image/s')");
  41.         btnDelete2.Attributes.Add("onclick", "javascript:return
  42.  ConfirmDelete('Image/s')");
  43.     }
  44.  
  45.  I need to execute this method:
  46.  //Remove Checked in CheckBox
  47.     private void ReInitializeCheckbox()
  48.     {
  49.         foreach (Control ctrl in myPanel.Controls)
  50.         {
  51.             ....
  52.                 CheckBox chkPhoto = (CheckBox)ctrl.FindControl(ctrl.ID);
  53.  
  54.                 if (chkPhoto.Checked)
  55.                     chkPhoto.Checked = false;
  56.             ...
  57.         }
  58.     }
  59.  
  60.   // As suggested in another forum, I tried this but when cancel is click,
  61.  it executed
  62.   //the GetSelectedPhotosForDeletion() method
  63.   function ConfirmDelete(szText)
  64.     {
  65.         var confirmed = confirm("Are you sure you want to delete the " +
  66.  szText + "?");
  67.  
  68.         if(confirmed)
  69.             return true;
  70.         else
  71.         {
  72.  
  73.          var allInputs = Form1.getElementsByTagName('INPUT'); //check all
  74.  input boxes
  75.  
  76.      for ( var i=0; i<allInputs.length; i++ )
  77.                  {
  78.                                            if ( allInputs.type ==
  79.  'checkbox'
  80.  )
  81.                                           {
  82.                                                 if ( allInputs.checked)
  83.                                                       allInputs.checked =
  84.  false;
  85.                                           }
  86.                                     }
  87.                                     //do the same for 'select' controls and
  88.  radio buttons
  89.                         return false;
  90.         }
  91.     }
  92.  
  93.  
  94.   //This gets executed
  95.   protected void btnDelete_Click(object sender, EventArgs e)
  96.     {
  97.               GetSelectedPhotosForDeletion();//even clicking cancel in
  98.  confirm this gets executed..
  99.     }
  100.  
  101.  
Thanks in advanced..

den2005

--
MCP Year 2005, Philippines


Oct 9 '06 #4

P: n/a
What error you got ? if you didn't get error , can you please uncheck
Disable Script Debugging (Ie and other) in IE's tools->iption->Advanced tab,
and rerun your application. It seems like you should get object not defined
error from javascript.

"den 2005" <de*****@discussions.microsoft.comwrote in message
news:F3**********************************@microsof t.com...
Thanks Baski for replying...

I tried what you suggested in question 1, it's not working, what is wrong
with this?

Inside Parent user control:

RichTextEditor1.SetEditorContent(dr["Contents"].ToString());

Inside RichTextEditor user control class:

public void SetEditorContent(string contents)
{
this.EditorContent = contents;
//Page.ClientScript.RegisterClientScriptBlock(this.G etType(),
"RunFunction", "setTxt('" + contents + "')");
Page.RegisterStartupScript("StartupScript", "setTxt('" + contents +
"')");
}

The second question has been resolved in another post on this same forum.
--
MCP Year 2005, Philippines
"Baski" wrote:
>
Question 1: How do you set the values from server-side to a
client-side
control or how do you execute a javascript function without a button
click
event?

What ever asp.net control post back to your server even handler
add
the following code

this.Page.RegisterStartupScript("StartupScript"," <script>YourJavascriptFunctionName()</script>");

when page post back this method will be called on page load, if needed ,
you
can also pass value to your javascripr function from server side.

like below

this.Page.RegisterStartupScript("StartupScript"," <script>YourJavascriptFunctionName('param1',
'param2')</script>");
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

since you are return true or false in your confirmation , your delete
button
event handler will be called back upon true,
there you can write your checkbox selection logic.
"den 2005" <de*****@discussions.microsoft.comwrote in message
news:84**********************************@microso ft.com...
Hi everybody,

Question 1: How do you set the values from server-side to a
client-side
control or how do you execute a javascript function without a button
click
event?
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1.                <td id="mam" height="180">
  2.                    <iframe id="NewsBody_rich"
  3. src="includes/MsgBody.htm"
  4. width="100%" height="100%"
  5.                        onblur="fillTxt()" style="font-family:
  6. Arial"></iframe>
  7.                </td>
  8. //Javascript function to be executed
  9.                function setTxt(szText)
  10. {
  11.   var State = new Object()
  12.   var aa;
  13.   NewsBody_rich.document.body.innerHTML = szText;
  14. }
  15.  

Question 2:
Expand|Select|Wrap|Line Numbers
  1. UserControl mentioned
  2. <%@ Control Language="C#" AutoEventWireup="true"
  3. CodeFile="AlbumDetailList.ascx.cs"
  4. Inherits="usercontrols_AlbumDetailList"
  5. %>
  6. <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  7.    <table id="tblMain" width="824" border="0">
  8.        ....
  9.       <tr>
  10.            <td>
  11.                <asp:Panel ID="pnlPhotos" runat="server" Height="100px"
  12. Width="824px">
  13.                </asp:Panel>
  14.            </td>
  15.        </tr>
  16.       ...
  17.   </table>
  18. </asp:Panel>
  19. Inside MasterPage:
  20. <script language="javascript" type="text/javascript">
  21. ....
  22.   function ConfirmDelete(szText)
  23.    {
  24.        var confirmed = confirm("Are you sure you want to delete the " +
  25. szText + "?");
  26.        if(confirmed)
  27.            return true;
  28.        else
  29.            return false;
  30.    }
  31. ....
  32. </script>
  33. //Add attributes to delete buttons
  34.    private void InitializeButtonAttributes()
  35.    {
  36.        btnDelete1.Attributes.Add("onclick", "javascript:return
  37. ConfirmDelete('Image/s')");
  38.        btnDelete2.Attributes.Add("onclick", "javascript:return
  39. ConfirmDelete('Image/s')");
  40.    }
  41. I need to execute this method:
  42. //Remove Checked in CheckBox
  43.    private void ReInitializeCheckbox()
  44.    {
  45.        foreach (Control ctrl in myPanel.Controls)
  46.        {
  47.            ....
  48.                CheckBox chkPhoto = (CheckBox)ctrl.FindControl(ctrl.ID);
  49.                if (chkPhoto.Checked)
  50.                    chkPhoto.Checked = false;
  51.            ...
  52.        }
  53.    }
  54.  // As suggested in another forum, I tried this but when cancel is
  55. click,
  56. it executed
  57.  //the GetSelectedPhotosForDeletion() method
  58.  function ConfirmDelete(szText)
  59.    {
  60.        var confirmed = confirm("Are you sure you want to delete the " +
  61. szText + "?");
  62.        if(confirmed)
  63.            return true;
  64.        else
  65.        {
  66.         var allInputs = Form1.getElementsByTagName('INPUT'); //check
  67. all
  68. input boxes
  69.     for ( var i=0; i<allInputs.length; i++ )
  70.                 {
  71.                                           if ( allInputs.type ==
  72. 'checkbox'
  73. )
  74.                                          {
  75.                                                if ( allInputs.checked)
  76.                                                      allInputs.checked
  77. =
  78. false;
  79.                                          }
  80.                                    }
  81.                                    //do the same for 'select' controls
  82. and
  83. radio buttons
  84.                        return false;
  85.        }
  86.    }
  87.  //This gets executed
  88.  protected void btnDelete_Click(object sender, EventArgs e)
  89.    {
  90.              GetSelectedPhotosForDeletion();//even clicking cancel in
  91. confirm this gets executed..
  92.    }
  93.  

Thanks in advanced..

den2005

--
MCP Year 2005, Philippines



Oct 9 '06 #5

P: n/a
Baski,
Where exectly would I expect to see the error, in browser window, or
Event viewer, I uncheck the Disable Script Debugging (Ie and other) and rerun
application, still no change...what do you meant by "you should get object
not defined error from javascript" exactly? I am not getting this error
message in browser window or event viewer...
--
MCP Year 2005, Philippines
"Baski" wrote:
What error you got ? if you didn't get error , can you please uncheck
Disable Script Debugging (Ie and other) in IE's tools->iption->Advanced tab,
and rerun your application. It seems like you should get object not defined
error from javascript.

"den 2005" <de*****@discussions.microsoft.comwrote in message
news:F3**********************************@microsof t.com...
Thanks Baski for replying...

I tried what you suggested in question 1, it's not working, what is wrong
with this?

Inside Parent user control:

RichTextEditor1.SetEditorContent(dr["Contents"].ToString());

Inside RichTextEditor user control class:

public void SetEditorContent(string contents)
{
this.EditorContent = contents;
//Page.ClientScript.RegisterClientScriptBlock(this.G etType(),
"RunFunction", "setTxt('" + contents + "')");
Page.RegisterStartupScript("StartupScript", "setTxt('" + contents +
"')");
}

The second question has been resolved in another post on this same forum.
--
MCP Year 2005, Philippines
"Baski" wrote:

Question 1: How do you set the values from server-side to a
client-side
control or how do you execute a javascript function without a button
click
event?

What ever asp.net control post back to your server even handler
add
the following code

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName()</script>");

when page post back this method will be called on page load, if needed ,
you
can also pass value to your javascripr function from server side.

like below

this.Page.RegisterStartupScript("StartupScript","< script>YourJavascriptFunctionName('param1',
'param2')</script>");

Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

since you are return true or false in your confirmation , your delete
button
event handler will be called back upon true,
there you can write your checkbox selection logic.
"den 2005" <de*****@discussions.microsoft.comwrote in message
news:84**********************************@microsof t.com...
Hi everybody,

Question 1: How do you set the values from server-side to a
client-side
control or how do you execute a javascript function without a button
click
event?
Question 2: How do you get response from a Confirm() popup window to
uncheck all server-side checkboxes placed in a panle of a web user
control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1.                 <td id="mam" height="180">
  2.                     <iframe id="NewsBody_rich"
  3.  src="includes/MsgBody.htm"
  4.  width="100%" height="100%"
  5.                         onblur="fillTxt()" style="font-family:
  6.  Arial"></iframe>
  7.                 </td>
  8.  
  9.  //Javascript function to be executed
  10.                 function setTxt(szText)
  11.  {
  12.    var State = new Object()
  13.    var aa;
  14.    NewsBody_rich.document.body.innerHTML = szText;
  15.  }
  16.  
Question 2:
Expand|Select|Wrap|Line Numbers
  1.  UserControl mentioned
  2.  <%@ Control Language="C#" AutoEventWireup="true"
  3.  CodeFile="AlbumDetailList.ascx.cs"
  4.  Inherits="usercontrols_AlbumDetailList"
  5.  %>
  6.  <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  7.     <table id="tblMain" width="824" border="0">
  8.         ....
  9.        <tr>
  10.             <td>
  11.                 <asp:Panel ID="pnlPhotos" runat="server" Height="100px"
  12.  Width="824px">
  13.                 </asp:Panel>
  14.             </td>
  15.         </tr>
  16.        ...
  17.    </table>
  18.  </asp:Panel>
  19.  
  20.  Inside MasterPage:
  21.  
  22.  <script language="javascript" type="text/javascript">
  23.  ....
  24.    function ConfirmDelete(szText)
  25.     {
  26.         var confirmed = confirm("Are you sure you want to delete the " +
  27.  szText + "?");
  28.  
  29.         if(confirmed)
  30.             return true;
  31.         else
  32.             return false;
  33.     }
  34.  ....
  35.  </script>
  36.  
  37.  //Add attributes to delete buttons
  38.     private void InitializeButtonAttributes()
  39.     {
  40.         btnDelete1.Attributes.Add("onclick", "javascript:return
  41.  ConfirmDelete('Image/s')");
  42.         btnDelete2.Attributes.Add("onclick", "javascript:return
  43.  ConfirmDelete('Image/s')");
  44.     }
  45.  
  46.  I need to execute this method:
  47.  //Remove Checked in CheckBox
  48.     private void ReInitializeCheckbox()
  49.     {
  50.         foreach (Control ctrl in myPanel.Controls)
  51.         {
  52.             ....
  53.                 CheckBox chkPhoto = (CheckBox)ctrl.FindControl(ctrl.ID);
  54.  
  55.                 if (chkPhoto.Checked)
  56.                     chkPhoto.Checked = false;
  57.             ...
  58.         }
  59.     }
  60.  
  61.   // As suggested in another forum, I tried this but when cancel is
  62.  click,
  63.  it executed
  64.   //the GetSelectedPhotosForDeletion() method
  65.   function ConfirmDelete(szText)
  66.     {
  67.         var confirmed = confirm("Are you sure you want to delete the " +
  68.  szText + "?");
  69.  
  70.         if(confirmed)
  71.             return true;
  72.         else
  73.         {
  74.  
  75.          var allInputs = Form1.getElementsByTagName('INPUT'); //check
  76.  all
  77.  input boxes
  78.  
  79.      for ( var i=0; i<allInputs.length; i++ )
  80.                  {
  81.                                            if ( allInputs.type ==
  82.  'checkbox'
  83.  )
  84.                                           {
  85.                                                 if ( allInputs.checked)
  86.                                                       allInputs.checked
  87.  =
  88.  false;
  89.                                           }
  90.                                     }
  91.                                     //do the same for 'select' controls
  92.  and
  93.  radio buttons
  94.                         return false;
  95.         }
  96.     }
  97.  
  98.  
  99.   //This gets executed
  100.   protected void btnDelete_Click(object sender, EventArgs e)
  101.     {
  102.               GetSelectedPhotosForDeletion();//even clicking cancel in
  103.  confirm this gets executed..
  104.     }
  105.  
  106.  
Thanks in advanced..

den2005

--
MCP Year 2005, Philippines


Oct 10 '06 #6

P: n/a
I thought you might get java script error in pop up browser window. ON your
javasctip function try to add alert message as first line and make sure it
got executed. If it shows the alert message , set the break point in your
javascript function and debug.

"den 2005" <de*****@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
Baski,
Where exectly would I expect to see the error, in browser window, or
Event viewer, I uncheck the Disable Script Debugging (Ie and other) and
rerun
application, still no change...what do you meant by "you should get object
not defined error from javascript" exactly? I am not getting this error
message in browser window or event viewer...
--
MCP Year 2005, Philippines
"Baski" wrote:
>What error you got ? if you didn't get error , can you please uncheck
Disable Script Debugging (Ie and other) in IE's tools->iption->Advanced
tab,
and rerun your application. It seems like you should get object not
defined
error from javascript.

"den 2005" <de*****@discussions.microsoft.comwrote in message
news:F3**********************************@microso ft.com...
Thanks Baski for replying...

I tried what you suggested in question 1, it's not working, what is
wrong
with this?

Inside Parent user control:

RichTextEditor1.SetEditorContent(dr["Contents"].ToString());

Inside RichTextEditor user control class:

public void SetEditorContent(string contents)
{
this.EditorContent = contents;
//Page.ClientScript.RegisterClientScriptBlock(this.G etType(),
"RunFunction", "setTxt('" + contents + "')");
Page.RegisterStartupScript("StartupScript", "setTxt('" +
contents +
"')");
}

The second question has been resolved in another post on this same
forum.
--
MCP Year 2005, Philippines
"Baski" wrote:
Question 1: How do you set the values from server-side to a
client-side
control or how do you execute a javascript function without a button
click
event?

What ever asp.net control post back to your server even
handler
add
the following code

this.Page.RegisterStartupScript("StartupScript"," <script>YourJavascriptFunctionName()</script>");

when page post back this method will be called on page load, if needed
,
you
can also pass value to your javascripr function from server side.

like below

this.Page.RegisterStartupScript("StartupScript"," <script>YourJavascriptFunctionName('param1',
'param2')</script>");

Question 2: How do you get response from a Confirm() popup window
to
uncheck all server-side checkboxes placed in a panle of a web user
control?

since you are return true or false in your confirmation , your delete
button
event handler will be called back upon true,
there you can write your checkbox selection logic.
"den 2005" <de*****@discussions.microsoft.comwrote in message
news:84**********************************@microso ft.com...
Hi everybody,

Question 1: How do you set the values from server-side to a
client-side
control or how do you execute a javascript function without a button
click
event?
Question 2: How do you get response from a Confirm() popup window
to
uncheck all server-side checkboxes placed in a panle of a web user
control?

I am using ASP.Net 2.0, Thanks. Need info...

Question 1:
Expand|Select|Wrap|Line Numbers
  1.                <td id="mam" height="180">
  2.                    <iframe id="NewsBody_rich"
  3. src="includes/MsgBody.htm"
  4. width="100%" height="100%"
  5.                        onblur="fillTxt()" style="font-family:
  6. Arial"></iframe>
  7.                </td>
  8. //Javascript function to be executed
  9.                function setTxt(szText)
  10. {
  11.   var State = new Object()
  12.   var aa;
  13.   NewsBody_rich.document.body.innerHTML = szText;
  14. }
  15.  

Question 2:
Expand|Select|Wrap|Line Numbers
  1. UserControl mentioned
  2. <%@ Control Language="C#" AutoEventWireup="true"
  3. CodeFile="AlbumDetailList.ascx.cs"
  4. Inherits="usercontrols_AlbumDetailList"
  5. %>
  6. <asp:Panel ID="pnlMain" runat="server" Height="600px" Width="824px">
  7.    <table id="tblMain" width="824" border="0">
  8.        ....
  9.       <tr>
  10.            <td>
  11.                <asp:Panel ID="pnlPhotos" runat="server"
  12. Height="100px"
  13. Width="824px">
  14.                </asp:Panel>
  15.            </td>
  16.        </tr>
  17.       ...
  18.   </table>
  19. </asp:Panel>
  20. Inside MasterPage:
  21. <script language="javascript" type="text/javascript">
  22. ....
  23.   function ConfirmDelete(szText)
  24.    {
  25.        var confirmed = confirm("Are you sure you want to delete the
  26. " +
  27. szText + "?");
  28.        if(confirmed)
  29.            return true;
  30.        else
  31.            return false;
  32.    }
  33. ....
  34. </script>
  35. //Add attributes to delete buttons
  36.    private void InitializeButtonAttributes()
  37.    {
  38.        btnDelete1.Attributes.Add("onclick", "javascript:return
  39. ConfirmDelete('Image/s')");
  40.        btnDelete2.Attributes.Add("onclick", "javascript:return
  41. ConfirmDelete('Image/s')");
  42.    }
  43. I need to execute this method:
  44. //Remove Checked in CheckBox
  45.    private void ReInitializeCheckbox()
  46.    {
  47.        foreach (Control ctrl in myPanel.Controls)
  48.        {
  49.            ....
  50.                CheckBox chkPhoto =
  51. (CheckBox)ctrl.FindControl(ctrl.ID);
  52.                if (chkPhoto.Checked)
  53.                    chkPhoto.Checked = false;
  54.            ...
  55.        }
  56.    }
  57.  // As suggested in another forum, I tried this but when cancel is
  58. click,
  59. it executed
  60.  //the GetSelectedPhotosForDeletion() method
  61.  function ConfirmDelete(szText)
  62.    {
  63.        var confirmed = confirm("Are you sure you want to delete the
  64. " +
  65. szText + "?");
  66.        if(confirmed)
  67.            return true;
  68.        else
  69.        {
  70.         var allInputs = Form1.getElementsByTagName('INPUT'); //check
  71. all
  72. input boxes
  73.     for ( var i=0; i<allInputs.length; i++ )
  74.                 {
  75.                                           if ( allInputs.type ==
  76. 'checkbox'
  77. )
  78.                                          {
  79.                                                if (
  80. allInputs.checked)
  81. allInputs.checked
  82. =
  83. false;
  84.                                          }
  85.                                    }
  86.                                    //do the same for 'select'
  87. controls
  88. and
  89. radio buttons
  90.                        return false;
  91.        }
  92.    }
  93.  //This gets executed
  94.  protected void btnDelete_Click(object sender, EventArgs e)
  95.    {
  96.              GetSelectedPhotosForDeletion();//even clicking cancel
  97. in
  98. confirm this gets executed..
  99.    }
  100.  

Thanks in advanced..

den2005

--
MCP Year 2005, Philippines



Oct 10 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.