Showing posts with label How To. Show all posts
Showing posts with label How To. Show all posts

How to store a single quote (') in a character variable in c#.

char ch='\'';
that is single cote \ single cote single cote.

How to call a javascript function through the radio button click. with parameter passing

Java script
----------------------------------------------------------------------------------------------------------

 function SelfRegd(state)
      {
      if(state =="Yes")
      document.getElementById('<%=pnlSelfRegd.ClientID%>').style.display='inline';
      else if(state=="No")
      document.getElementById('<%=pnlSelfRegd.ClientID%>').style.display='none';
      }

Aspx
------------------------------------------------------------------------------------------------------------

<asp:RadioButton ID="rbtSelfRegtYes" onclick="return  SelfRegd('Yes');" runat="server" Text="Yes" GroupName="SelfRegt" />
                                    <asp:RadioButton ID="rbtSelfRegtNo" onclick="return  SelfRegd('No');" runat="server" Text="No" GroupName="SelfRegt" />


--------------------------------------------------------------------------------------------------------
OR
from code behind

pageload
---------------------------------------------------------------------------------------------------------

rbtSelfRegtYes.Attribute.Add("onclick","return SelfRegd('Yes')");


How to call a java script function by fire dropdownlist on selectedindex change event

from the pageload
-------------------------------------------------------------------------------------------------------------
 dropdownList.Attributes.Add("onChange", "return OnSelectedIndexChange();");

Inside javascript
--------------------------------------------------------------------------------------------------------------
   function OnSelectedIndexChange()
     {
         
      }

How to do change style in onmouseover and onmouseout from the code behind

pnlAdded.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor = 'Yellow';this.style.color = 'Black';");
               pnlAdded.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor = 'Red';this.style.color = 'White';");


 lnk.Attributes.Add("onmouseover", "this.style.textDecoration='none';this.style.fontWeight='bold';")
                    'lnk.Attributes.Add("onmouseover", "this.style.textDecoration='none'")
                    lnk.Attributes.Add("onmouseout", "this.style.fontWeight='normal';")
pnlAdded is id for the panel .
lnk is id for linkbutton

How to access and change the html controls background color.

 HtmlTableRow thTopPanel = (HtmlTableRow)e.Item.FindControl("thTopPanel");
                thTopPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Green");

How to access the html controls from the code behind

HtmlTableRow thTopPanel = (HtmlTableRow)e.Item.FindControl("thTopPanel");

thTopPanel->id of the th of the table.

HtmlTableCell htc = (HtmlTableCell)e.Item.FindControl("dateLtlContainer"); 


dateLtlContainer->id for td of the table.

To make an asp control visible true and false through javascript with out page refresh

 <asp:Panel style="display:none;" ID="pnlFileAttachment" runat="server">
          <table>  <tr>  <td>    ANY CONTENT </td>  </tr>   </table>
    </asp:Panel>
HERE IF IN PLACE OF style="display:none;" WE WILL GIVE VISIBILITY =FALSE THEN WE CAN NOT ACCESS THIS PANEL CONTROL FROM THE JAVASCRIPT BECAUSE WHEN WE MAKE A CONTROL DISPLAY NONE ITS NOT RENDER INTO THE PAGE ,SO WE WILL GET THE OBJECT NOT FOUND EXCEPTION IN THE JAVA SCRIPT
   <td>    <asp:RadioButton ID="rbtFileAttachmentYes" onclick="return  AttachmentPanel('Yes');" runat="server" Text="Yes" GroupName="FileAttachment" />
     <asp:RadioButton ID="rbtFileAttachmentNo" onclick="return AttachmentPanel('No');" runat="server" Text="No" GroupName="FileAttachment"  />
 </td>
 <script language="javascript" type="text/javascript">    function AttachmentPanel(state)
    {
   if(state =="Yes")
    document.getElementById('<%=pnlFileAttachment.ClientID%>').style.display='inline';
    else if(state =="No")
     document.getElementById('<%=pnlFileAttachment.ClientID%>').style.display='none';
    }
</script>
 IN THE PAGE LOAD
-----------------------------------------------------------------------------------------------
   if (ds.Tables[0].Rows[0]["AllowCommentsToEvents"].ToString() == "Yes")   
       {
                rbtCommentToEventYes.Checked = true;
                pnlCommentToEvent.Style.Add(HtmlTextWriterStyle.Display, "inline");
            }            else if (ds.Tables[0].Rows[0]["AllowCommentsToEvents"].ToString() == "No")
            {
                rbtCommentToEventNo.Checked = true;
                pnlCommentToEvent.Style.Add(HtmlTextWriterStyle.Display, "none");
            }
 IF WE NEED TO CHANGE THE VISIBILITY IF ANY CONTROLS FROM JAVA SCRIPT WE HAVE TO USE THIS PROCEDURE .
WHEN RADIO BUTTON YES WILL BE CHECKED THE PANEL  WILL BE DISPLAYED AND WHEN THE RADIO BUTTON NO WILL BE CHECKED THE PANEL WILL NOT BE DISPLAYED.

How to set password for the sqlserver user by query

alter login username or userid with password='Give password inside single quote',check_policy=off

HOW TO ENCRYPT AND DECRYPT A STRING IN C#

string EncryptedString= Encrypt("STRING VALUE");
------------------------------------------

public string Encrypt(string Data)
{
 SHA1Managed shaM = new SHA1Managed();
 Convert.ToBase64String(shaM.ComputeHash(System.Text.Encoding.ASCII.GetBytes(Data)));
 byte[] eNC_data = System.Text.ASCIIEncoding.ASCII.GetBytes(Data);
 string eNC_str = Convert.ToBase64String(eNC_data);
 return eNC_str;
}

string  DecryptedString= Decrypt("Encryptedsrting");
------------------------------------------------------------------------------------------------
string original_string=Decrypt(eNC_str);

private string Decrypt(string Data)
{
 byte[] dEC_data = Convert.FromBase64String(Data);
 string dEC_Str = System.Text.ASCIIEncoding.ASCII.GetString(dEC_data);
 return dEC_Str;
}

OPENING THE PAGE IN ANOTHER BROWSER USING JAVA SCRIPT

 FROM JAVASCRIPT
-----------------

function Openwindow(id)
        {
       
        a1=window.open("desktopModules/DocuInfo.aspx?&itemid="+id,"MyWindow", 'left=300,top=200,width=500,height=230,scrollbars=yes,toolbar=0,resizable=0');
        a1.focus();
        }

FROM ASPX
---------------

<a href='#'>
<img alt="open" id="tes" style="border: 0" name="test" src="images/images1.jpg" onclick="javascript:Openwindow('<%# DataBinder.Eval(Container.DataItem,"ItemId") %>');"           height="10" width="10" align="middle"></a>


<a href='#'>-># ONLY SHOW THE LINK WHEN MOUSE OVER.ON CLICK IN IT NOTHING WILL HAPPEN

HOW TO CHANGE THE BACKGROUND COLOR OF A LINK BUTTON ON MOUSE OVER

style type="text/css">
    .customhover a
    {
                background-color: Transparent;
    }
    .customhover a:hover
    {
        background-color: #CCFFFF;
        color:Black;
          border:solid 1px black;
       
    }
   </style>

<td>
   <div class="customhover">
    <asp:LinkButton runat="server" ID="lnkBtnKitDefinition" Font-Size="11px" Font-Underline="False"
                                                                                    Font-Bold="false" Font-Names="Verdana" Text="Kit Definitions"></asp:LinkButton>
</div>
 </td>

HOW TO CHANGE THE IMAGE SOURCE OF AN IMAGE BUTTON ON MOUSE OVER

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

imgBtn_Rename.Attributes.Add("onmouseover", "this.src='images/icons/rename2.gif';")
imgBtn_Rename.Attributes.Add("onmouseout", "this.src='images/icons/rename.gif';")

  End Sub

<asp:ImageButton ID="imgBtn_Rename" runat="server" ImageUrl="~/images/icons/rename2.gif"
                    AlternateText="Rename" Height="20px"></asp:ImageButton>

HOW TO CALL A JAVASCRIPT FUNCTION FROM CODE BEHIND

   Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

imgBtnViewAll.Attributes.Add("onclick", "return filesSelected('View');")

End Sub

<asp:ImageButton ID="imgBtnViewAll" runat="server" ImageUrl="~/images/docimages/move3.jpg"
                    AlternateText="Move To" Height="20px"></asp:ImageButton>

HERE WHEN IMAGE BUTTON WILL BE CLICKED THE  filesSelected METHOD PRESENT IN THE JAVA SCRIPT WILL BE CALLED WITH A STRING PARAMETER.

JAVA SCRIPT IN CODE BEHIND

Dim jscript As String = Nothing
            jscript += "<script>"
            jscript += "window.open('GetLogDetails.aspx','_blank')"
            jscript += "</script>"
            RegisterClientScriptBlock("submission", jscript)