|
Want to do clienside validation on a textbox control. This textbox can represent two data types depending on an associtate checkbox. So if checkbox is checked the validation should do (a) and if off do (b)
In the javascript funtion below I do a getElementForID("chkBox1")
However if I want this to be a global routine I don't know what the checkBox would be
and preferably I'd like to pass an Integer so I could do multiple validations on this control or others. The "Sender" parameter seems to be my textbox, So question is how do I setup the ClientValidationFuntion property of the validator to pass an integer?
My custom validator is setup like this
<asp:CustomValidator ID="lsdCustomVal" ControlToValidate="txtBox1" runat="server"
ClientValidationFunction= "validateLSDControl"></asp:CustomValidator>
in my external js file I have >>
function validateLSDControl( sender, args)
{
var expr1 = "[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9]";
var expr2 = "[a-z]-[0-9][0-9][0-9]-[A-Z]/[0-9][0-9]";
var x = document.getElementById(sender.controltovalidate);
var chkbox = document.getElementById("chkBox1");
var smsg = "";
if (chkbox.checked) {
var patt1 = new RegExp(expr, "g");
smsg = "expr1 Invalid";
}
else {
var patt1 = new RegExp(nts, "g");
smsg = "expr2 Invalid";
}
var result = false;
if (x != null) {
var s = x.value;
if (s.match(patt1))
{
// alert("it worked");
result = true;
}
else
alert(smsg);
}
args.isValid = result;
}
|
|
|
|
|
if you are using masterpage then you must below code to access asp control
like
document.getElementById('<%= chkBox1.ClientID%>');
or
change the form's default name according you and access the control by
FORMNAME.GETELEMENTBYID
plz check it.
Rajeev Kr. Sharma
Sr. Software Engineer
E-Meditek Solutions Ltd.
http://www.emeditek.co.in/
|
|
|
|
|
Below is my databse table..
I can populate this data into the UI Page..
My task is to automatically delete the columns which has '0'(zero) value...and i have to delete the first row of my table...
Hear i am not going to use any itemtemplate column..
I have to write some code in codebehind..
JurisdictionID JurisdictionDescription Year1 Year2 Year3 Year4 Year5 Year6 Year7
2005 2006 2009 0 0 0 0
AL Alabama 0 0 6 0 0 0 0
AK Alaska 2 0 0 0 0 0 0
Could Anyone suggest me ..How to proceed further in detail with some code...
modified on Monday, June 1, 2009 4:24 PM
|
|
|
|
|
foreach (GridViewRow Row in grd.Rows)
{
for (int i = 0; i<7; i++)
{
if (Row[i].ToString().Equals("0"))
{
grd.Columns.Remove(Row[i]);
}
}
}
I have not tested this code. Let me know if it works or not so as to fix the errors. Regards
|
|
|
|
|
hey..i am getting some errors..when am using that code..
in which method we have to write tht code..
i wrote in...
public void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
i am getting errors like this..
1) 'System.Data.DataRow.DataRow(System.Data.DataRowBuilder)' is inaccessible due to its protection level
2) Cannot apply indexing with [] to an expression of 'System.Web.UI.WebControls.GridViewRow'
actually am poor in c# technologies..could you sen dme solution fot this..
|
|
|
|
|
Sorry, I was closing from work when I posted. This should work:
foreach (GridViewRow Row in GridView1.Rows)
{
for(int i=0; i < 7; i++)
{
if (Row.Cells[i].Text == "0")
{
GridView1.Columns.Remove(GridView1.Columns[i]);
}
}
}
I called up this function from a button which I created. You can place it within the GridView1_RowDeleting if you wish without problems.
As per deleting first row, I suggest deleting it from database first (using sql query) and re-binding your gridview.
|
|
|
|
|
hey..thnx for ur reply..
i am writting the code in the row delete event only...
i am not getting any errors..when i execute this code...somehow am unable to delete the columns....
is there any pother way to do..?
|
|
|
|
|
If what you want to do is to delete a column from the underlying database table I'm not sure I can help you on that.
If what you want h/ever is to simply hide the column from the GridView this should work otherwise you can replace GridView1.Columns.Remove(GridView1.Columns[i]); with GridView1.Column[i].Visible = false;
I've tested the previous code and it worked.
Why not post more code for us to see where you're getting it wrong?
|
|
|
|
|
by using above syntax also..i can't see anychange in the table..i can see all the columns..the 0(zero) value cell columns are not hiding..
actullt my task is to delete those columns..am unable to do that..
atleast i want to try with hiding those columns..
below i copied my code of populating data into gridview and the rowdelete event..
protected void Page_Load(object sender, EventArgs e)
{
PopulateGrid();
}
public void PopulateGrid()
{
SqlConnection sqlConn = null;
SqlDataAdapter da = null;
try
{
string connString = null;
SqlCommand cmd1;
connString = System.Web.Configuration.WebConfigurationManager.AppSettings["SqlServerConnectionString"];
sqlConn = new SqlConnection(connString);
sqlConn.Open();
cmd1 = new SqlCommand("[MED].[usp_SelectAllSDNCounts]", sqlConn);
cmd1.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd1);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
finally
{
sqlConn.Close();
da.Dispose();
da = null;
}
}
public void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
foreach (GridViewRow Row in GridView1.Rows)
{
for(int i=0; i<11; i++)
{
if (Row.Cells[i].Text == "0")
{
GridView1.Columns[i].Visible=false;
}
}
}
}
|
|
|
|
|
Change:
protected void Page_Load(object sender, EventArgs e)
{ PopulateGrid();
}
to:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
PopulateGrid();
}
}
Does this help? 
|
|
|
|
|
no..hmmm it remains the same..i can see the table with all column ..
if u want to know my design page ..see below..
%@ Page Language="C#" AutoEventWireup="true" CodeFile="MedPending.aspx.cs" Inherits="Maintenance_MedPending" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server" >
<div>
</div>
<asp:Panel ID="Panel1" runat="server" style="position:absolute; left: 184px; top: 82px;" Width="740px" CssClass="borderPanel" Height="177px">
<table style="width:600px;" class="borderPanel">
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" HeaderStyle-HorizontalAlign="Center" Width="592px" style="position:absolute; left: 68px; top: 26px;" CssClass="GridRowGrayBorder" >
<RowStyle CssClass="GridRow" />
<HeaderStyle CssClass="HeaderRow" HorizontalAlign="Center" />
<EditRowStyle CssClass="GridRow" />
</asp:GridView>
</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
</html>

|
|
|
|
|
1. Try putting a breakpoint in the code provided and see if the Row's Cell Text ever evaluates to "0". Does it ever enter the function i gave you?
2. Have you hooked the Row_Deleting method to the control calling it? If not add:
OnRowDeleting = "GridView1_RowDeleting" to this:
<gridview id="GridView1" runat="server" headerstyle-horizontalalign="Center" width="592px" style="position:absolute; left: 68px; top: 26px;" <b="">OnRowDeleting = "GridView1_RowDeleting" CssClass="GridRowGrayBorder">
Or alternatively in Page_Load add:
GridView1.RowDeleting+=new GridViewDeleteEventHandler(GridView1_RowDeleting);
Hope this helps
|
|
|
|
|
If this suggestion helped you, kindly say so, so the thread will be marked as resolved.
|
|
|
|
|
Hello there!
I have very strange problem and I hope someone will help me because I'm running out of time. So, the deal is - I'm working on a project for my graduation, which is a web site, connected to a SQL Database. It was working perfectly, until I decided to make users and roles. I run the aspnet_regsql.exe, which created in my database some tables to manage the users, but when I try to configure the roles through Web Site Administration Tool it cannot find my database...It's strange because when I execute my queries it works fine.
Can anyone tell me why the Web Site Administration Tool doesn't see my database?
Thanks in advance!!!
|
|
|
|
|
I guess your Web Site Administration Tool hasn't got the rights to show you the database.
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Hi There,
I am retrieving Hidden Field value through javascript but it is showing me one error that is
document.getElementById("ctl00_ContentPlaceHolder1_hfUpd") has no properties
I tried all following ways also:-
document.getElementById("hid").value
document.getElementById('hid').value
document.getElementById("ctl00_ContentPlaceHolder1_hfUpd").value //Using ControlID
Previously I tried used following code and it working fine.
document.getElementById("hid").value
But This Code Is Not Working.Is There any problem of Content Place Holder.
My Code To retrieve value:-
var hidflag=document.getElementById('<%=hfUpd.ClientID%>').value
|
|
|
|
|
try $get('<%=hdf.ClientID%'>.value
|
|
|
|
|
$get is an AJAX function that is simply shorthand for document.getElementById
only two letters away from being an asset
|
|
|
|
|
Good day,
I've decided to implement articles reading/writing in my webapp. So i sat down and started thinking about how should i accomplish my goal. I came up with the following idea:
1. Article List / Search form
2. Article Add / Edit form
3. Article Detail form.
However i'm not quite sure "what is the whole picture behind the scenes". I was thinking of the following:
When composing / editing an article there should be a input text control ( Multiline textbox for example ) which acceps HTML. My question here is: Is it acceptable to develope that kind of a control, since only the editors and administrators will be able to access this page. Is that the right way to achieve this ( html gives a really big power when wrtiting article ... but it could be harmful in the wrong hands ) ?
The markup will be stored in MS SQL database.
When displaying the markup in the article, should i use a "Label" control to achieve this. Since this control is rendered like a it can be really useful to display HTML. Is this the right way ?
Thanks in advance.
Regards, Hris
|
|
|
|
|
Hello Friends,
I've a folder named "noida" in my project and some pages in that folder And now i've to open those pages like http://noida.saamstesting.com/Page1.aspx .
|
|
|
|
|
|
I have login page with both button click and text changed event having same code.
If i disable the code on buttonclick event and enable the textcox changed event,if i click on the button, page is redirecting to the next page which is wrong.Why it is happening?
Which event calls first button click event or textchanged event.
so i am testing both cases.
Otherwise wats the solution to do both the ways?
I wanted to login either through button click or by click 'enter'.
If u r free please give me the reason and solution
kissy
|
|
|
|
|
You should set the login button as the default button on your page. The you don't have to handle the textchange event from your textbox, the enter key will cause the button click event.
only two letters away from being an asset
|
|
|
|
|
|
Do you even look at other responses before posting yours? Your response was redundant, stop clouding up the forum with such nonsense.
only two letters away from being an asset
|
|
|
|