How to create dynamic javascripts in server side code based on server side variables?
Here’s and example: VB.NET Dim value As String = ‘pic1.jpg’ Button1.Attributes(‘onMouseOver’) = ‘alert( ’’ + value + ‘’);’ C# string value = ‘pic1.jpg’; Button1.Attributes[‘onMouseOver’] = ‘alert( \” + value + ‘\’);’ ;
How to get the confirmation of Yes/No from a javascript pop-up and display the value on the page
Code Behind Button1.Attributes.Add(‘onclick’, ‘getMessage()’) Client Side <SCRIPT language=javascript> function getMessage() { var ans; ans=window.confirm(’Is it your confirmation…..?’); if (ans==true) { document.Form1.hdnbox.value=’Yes’; } else { document.Form1.hdnbox.value=’No’;} } </SCRIPT> To display the Yes/No value selected by user, in your code behind file: Response.Write(Request.Form(‘hdnbox’))
Why can’t I open a new browser window from within server code?
Server code executes on Server, whereas the new window is created on the client. You need to use client-side script to open new window.
How to assign a text to Checkbox control and know which checkbox is selected
<asp:CheckBox id=’chkTips’ style=’Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 64px’ runat=’server’ Text=’Tips’></asp:CheckBox> <asp:CheckBox id=’chkTricks’ style=’Z-INDEX: 102; LEFT: 32px; POSITION: absolute; TOP: 112px’ runat=’server’ Text=’Tricks’></asp:CheckBox> <asp:CheckBox id=’chkFaqs’ style=’Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 160px’ runat=’server’ Text=’Faqs’></asp:CheckBox> <asp:Button id=’btnSelect’ style=’Z-INDEX: 104; LEFT: 40px; POSITION: absolute; TOP: 224px’ runat=’server’ Text=’Select’></asp:Button> VB.NET Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’Put user code to initialize the page here If Not Page.IsPostBack Then End If End Sub Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click Dim ctl As Control Dim strchkSelected As String For Each ctl In Page.Controls(1).Controls If TypeOf ctl Is CheckBox Then if CType(ctl, CheckBox).Checked Then strchkSelected += CType(ctl, CheckBox).Text + ‘ ‘ End If End If Next Response.Write(strchkSelected) End Sub C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if (!Page.IsPostBack ) { } } private void btnSelect_Click(object sender, System.EventArgs e) { string strchkSelected=” ; foreach (Control ctl in Page.Controls[1].Controls ) { CheckBox chk = ctl as CheckBox ; if (chk!=null) { if (chk.Checked ) { strchkSelected += chk.Text + ‘ ‘ ; } } } Response.Write (strchkSelected); }
How to determine the Windows User from a Web form Application
Use the System.Security.Principal namespace. VB.NET dim wp as WindowsPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()) Response.Write(wp.Identity.Name) C# WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent()); Response.Write(wp.Identity.Name);