Tim Maxey .NET Technology Blog & Resources
C# .NET Code
Posts about C# code
Here is the easiest way to hide or rather disable the asp.net button control, or any other control for that matter, take this:
<div id="dwait" style="display:none">please wait, creating account...</div>
<div id="dBut"><asp:Button ID="Button1" runat="server" Text="Submit" OnClientClick="HideMe();" /></div>
function HideMe() {
var dw = document.getElementById("dwait");
var db = document.getElementById("dBut");
db.style.display = "none";
dw.style.display ="block";
}
When the asp.net button is clicked, it just hides the div of the button, or imagebutton (if you want) and shows the "wait" div. In the wait div you could put/style it however, like with an animated waiting or whatever... Enjoy!
Hi there guys, had an issue with WebForm_DoPostBackWithOptions vs __doPostback. WebForm_DoPostBackWithOptions started showing up on a page and not showing up on other .NET pages. It was a pain in my butt! Because WebForm_DoPostBackWithOptions wasn't working, all my linkbutton had this javascript function rendered and none of the events were firing!
So after looking around I found out that I had some panels that were hidden on the page. And in one of those panels, I have a validation control, if a validation control is "hidden" on the page (the panel's visibility is set to false and later made visible) then...
My webservice call to, example: service1.asmx/myfunction just wasn't working on the server, but on my local box it worked great, so I had to add entries in the web config...
This needs to go between your <system.web> tags in the web.config
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
I had an ANNOYING problem with Visual Studio 2008 and the AjaxControlToolkit.dll. Seemed like if I had an Update Panel on the aspx age, I would get asked if I wanted to replace the AjaxControlToolkit.dll. ANNNOYING, so I did some searching and finally did this:
1. In VS 2008 I had to right click on the toolbar and choose the option "choose items," then I sorted the the .NET Framework Components and unchecked the AjaxControlToolkit version version 3.0.1xxx and keep the 3.0.2xxx.
2. Next I went to the property page of the project and references and removed the AjaxControlToolkit reference, then I...
Great code I found for maxlength issue with .NET textboxes. .NET textboxes, if TextMode is set to MutilLine, the maxlength property just doesn't work, sux. So after playing around with different soloutions. I found this on, thanks to a guy named "Leo." So a big thanks to him!
Add this function in JavaScript on your page, I stuck it my "functions.js" file I include on the page anyway.
function checkMaxLen(txt,maxLen) {try{if(txt.value.length > (maxLen-1)) {var cont = txt.value;txt.value = cont.substring(0,(maxLen -1));return false;};}catch(e){}}
Then on the textbox use something like this:
<asp:TextBox runat="server" ID="txtComments" CssClass="comment_textbox" Height="75px" TextMode="MultiLine" onkeyup="return checkMaxLen(this,151)"></asp:TextBox>
Notice the function passes the textbox...
I went to an interview and basically ended up telling the guy that the company was not for me. But I did learn something:
I found out how to track an email being opened, pretty cool trick, ready for this awesome trick?
When the email gets created in an app, a small 1px img is saved on the server, a guid.gif, transparent gif. guid meaning like der35d288d5jsk32.gif
This gif is added to the email address and when the email is opened, the gif is pulled from the server, and on the server the folder has a listener and when that gif is requested...
First, throw this into a Mater Page, or the page you have your CheckBoxList control on...
<script type="text/javascript">
function uStyle(cb) {
cb.parentNode.style.backgroundColor =
cb.checked ? "yellow" : "" ;
cb.parentNode.style.color =
cb.checked ? "blue" : "" ;
}
</script>
Now I databind the CheckBoxList, so if you do not (you just loaded values manually) then take the the CheckBoxList1.DataBind reference out...
I have a Sub I call on the Page Load event: If Not Page.IsPostBack then... "AddScript"
Protected Sub AddScript()
CheckBoxList1.DataBind
Dim MyItem As ListItem
For Each MyItem In CheckBoxList1.Items
MyItem.Attributes.Add("onclick", "uStyle(this);")
Next
End Sub
This seems to work a lot better than having to use an Update Panel and a ONSELECTED_CHANGE event...
I was messing around with the checkbox list want simulate a dropdown list with checkboxes in it. A buddy of mine said to try the checkbox list inside a div with scroll bars. Well I did not like the scroll bar on the bottom (horizontal). So I found this:
<div style="width:300px;height:100px;overflow-x: hidden;overflow-y:scroll;overflow:-moz-scrollbars-vertical !important;">
CHECKBOX LIST HERE
</div>
Note the !important is a css hack to tell the browser which tag to use depending upon Firefox or IE.... Cool at any rate, works like a champ... Then when a user "checks" the checkbox for one or more selections, you can stick the list in...
// ########### START CODE ######################################
public DataSet CreateDataSet(string strSQL)
{
System.Data.SqlClient.SqlConnection scnnNW = new System.Data.SqlClient.SqlConnection(GetConnectionString("connYourConnection"));
// A SqlCommand object is used to execute the SQL commands.
System.Data.SqlClient.SqlCommand scmd = new System.Data.SqlClient.SqlCommand(strSQL, scnnNW);
// A SqlDataAdapter uses the SqlCommand object to fill a DataSet.
System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(scmd);
// Create and Fill a new DataSet.
DataSet ds = new DataSet();
sda.Fill(ds);
scnnNW.Close();
scnnNW.Dispose();
return ds;
}
// ########### END CODE ######################################
This function is used to get the connection form the .config file...
// ########### START CODE ######################################
static string GetConnectionString(string name)
{
// Assume failure.
string returnValue = null;
// Look for the...
Wanted to post a for loop in a dataset, I will post the dataset function as well...
foreach (DataRow dr in ds.Tables[0].Rows)
{
//do something with the data
if (dr["Field1"] = 1)
{
//do something
}
else if (dr["Field2"] = 1)
{
//do something
}
else if (dr["Field3"] = 1)
{
//do something
}
}
Full C# .NET Code Archive