Thursday, March 29, 2012
Newbie : Adding an onclick event to server control, prevents postback.??
I have a .net page that basically has two buttons on it. Each
button when
rendered by the server basically seem to have a type of "SUBMIT". What
i want is to be able to disable one of the buttons when a user clicks
on it and have the server process the operation and then renable it
went it's done.
I added the following piece of code to my Page_Load event.
MyButton.Attributes.Add("onclick", "this.disabled=true;");
This worked fine except that my event handler in the code-behind,
ExportButton_Click is not fired and so nothign happens except for the
button being disabled. Can someone give me detailed information on how
this can be done as I'm relatively new to C# , Javascript and .Net.
I was reading about the RegisterOnSubmit statement and such but it
did not
seem to work. What am I missing? What is an easy way to accomplish
this?
Code snippets/ links much appreaciated.
Thanksyes this is a problem.
one way around this is to hide the button instead.
if looks a bit stupid but you could have a disabled button which is hidden
until you click and hide the real button.
a bit mickey mouse but what can you do?
if you find a better way, please post it.
a
"Dr Deadpan" <drdeadpan@.yahoo.com> wrote in message
news:a944d23e.0311201528.32794f68@.posting.google.c om...
> Hi,
> I have a .net page that basically has two buttons on it. Each
> button when
> rendered by the server basically seem to have a type of "SUBMIT". What
> i want is to be able to disable one of the buttons when a user clicks
> on it and have the server process the operation and then renable it
> went it's done.
> I added the following piece of code to my Page_Load event.
> MyButton.Attributes.Add("onclick", "this.disabled=true;");
> This worked fine except that my event handler in the code-behind,
> ExportButton_Click is not fired and so nothign happens except for the
> button being disabled. Can someone give me detailed information on how
> this can be done as I'm relatively new to C# , Javascript and .Net.
> I was reading about the RegisterOnSubmit statement and such but it
> did not
> seem to work. What am I missing? What is an easy way to accomplish
> this?
> Code snippets/ links much appreaciated.
> Thanks
Instead of adding an "onClick" attribute to the button,
why not just disable it from the buttons click event?
ie. myButton.Enabled = False
I guess what you are trying to achieve is to prevent the
user from clicking the button more than once.
You should also make sure you have wired up your event
handlers for the button.
eg. protected WithEvents btnMyButton As Button
protected sub btnMyButton_Click() Handles btnMyButton.Click
end sub
This is VB code, but you need to make sure you declare
your button using 'WithEvent', and wire up the proper
event (using the 'Handles' statement) to the method that
will be handling the event.
It might also be a good idea to set the AutoEventWireup
directive in your .aspx page to False, otherwise your
event will fire twice.
Hope this helps
>--Original Message--
>Hi,
> I have a .net page that basically has two buttons on
it. Each
>button when
>rendered by the server basically seem to have a type
of "SUBMIT". What
>i want is to be able to disable one of the buttons when a
user clicks
>on it and have the server process the operation and then
renable it
>went it's done.
> I added the following piece of code to my Page_Load
event.
>MyButton.Attributes.Add("onclick", "this.disabled=true;");
> This worked fine except that my event handler in the
code-behind,
>ExportButton_Click is not fired and so nothign happens
except for the
>button being disabled. Can someone give me detailed
information on how
>this can be done as I'm relatively new to C# , Javascript
and .Net.
> I was reading about the RegisterOnSubmit statement and
such but it
>did not
>seem to work. What am I missing? What is an easy way to
accomplish
>this?
> Code snippets/ links much appreaciated.
>Thanks
>.
"Rory" <anonymous@.discussions.microsoft.com> wrote in message news:<069e01c3aff6$1699ce20$a401280a@.phx.gbl>...
> Instead of adding an "onClick" attribute to the button,
> why not just disable it from the buttons click event?
> ie. myButton.Enabled = False
I cannot do this as it won't work. What the above will do, is disable
the button once it gets bakc to the client. All the while while the
server is actually running the code in the event handler, the button
will remain Enabled and will become disabled once the code behind is
done - definitely not what I wnat. I read a post earlier on about
doing it an easier way somewhere.
Please, all you guru's , keep the comments coming..
DrD
Monday, March 26, 2012
Newbie : Updating problem with Datagrid
I have a page with a datagrid control. What I would like to do is when
I click on the update statement, I will update to the datagrid. However
the problem I am facing currently is when I click on update, the value
which I got from the controls generated by the datagrid edit template
is empty. Is there something I am missing out on? I have attached the
source codes below, please advice. Thanks!
Web User Control :
<asp:DataGrid id="participateGrid" runat="server"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="1"
Width="100%" BorderColor="White" BorderStyle="None"
OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
ShowHeader="True">
<HeaderStyle BackColor="#dedfde" CssClass="tableLabel"></HeaderStyle>
<ItemStyle CssClass="tableItem" BackColor="#f7e7e7"></ItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Outlet">
<EditItemTemplate>
<asp:DropDownList ID="ddlOutlet" Runat="server">
<asp:ListItem>...</asp:ListItem>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remarks">
<EditItemTemplate>
<asp:TextBox id="txtRemarks" TextMode="MultiLine" Rows="2"
Columns="15" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" EditText="<img
src='editimage.jpg'>" UpdateText="<img src='updateimage.gif'>"
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
Text="<img src='delete.gif'"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
<asp:ImageButton ImageUrl="image.gif" id="btn_new"
runat="server"></asp:ImageButton
This is the codebehind file update method :
protected void Update (object sender, DataGridCommandEventArgs e)
{
DropDownList outlet = (DropDownList)e.Item.Cells[0].FindControl
("ddlOutlet");
TextBox remarks = ((TextBox)e.Item.Cells[1].FindControl
("txtRemarks"));
DataRow dr = dt.Rows[e.Item.DataSetIndex];
dr["Outlet"] = outlet.SelectedItem.Text;
dr["Remarks"] = remarks.Text;
saveData();
participateGrid.EditItemIndex = -1;
BindGrid();
}
private void saveData ()
{
//stores the information in a viewstate
ViewState ["Participate"] = dt;
}
//bind the data
private void BindGrid()
{
participateGrid.DataSource = dv;
participateGrid.DataBind();
}Are u binding your datagrid on page load? Page load event occurs before
datagrid update event.
If your answer is yes, control postback on your page load something like
this:
if (!IsPostBack)
{
BindGrid();
}
--
Thanks,
Yunus Emre ALPZEN
<ycquak@.gmail.com> wrote in message
news:1107496691.787654.33590@.c13g2000cwb.googlegro ups.com...
> Hi,
> I have a page with a datagrid control. What I would like to do is when
> I click on the update statement, I will update to the datagrid. However
> the problem I am facing currently is when I click on update, the value
> which I got from the controls generated by the datagrid edit template
> is empty. Is there something I am missing out on? I have attached the
> source codes below, please advice. Thanks!
> Web User Control :
> <asp:DataGrid id="participateGrid" runat="server"
> AutoGenerateColumns="False" CellPadding="1" CellSpacing="1"
> Width="100%" BorderColor="White" BorderStyle="None"
> OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
> ShowHeader="True">
> <HeaderStyle BackColor="#dedfde" CssClass="tableLabel"></HeaderStyle>
> <ItemStyle CssClass="tableItem" BackColor="#f7e7e7"></ItemStyle>
> <Columns>
> <asp:TemplateColumn HeaderText="Outlet">
> <EditItemTemplate>
> <asp:DropDownList ID="ddlOutlet" Runat="server">
> <asp:ListItem>...</asp:ListItem>
> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn HeaderText="Remarks">
> <EditItemTemplate>
> <asp:TextBox id="txtRemarks" TextMode="MultiLine" Rows="2"
> Columns="15" Runat="server"></asp:TextBox>
> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:EditCommandColumn ButtonType="LinkButton" EditText="<img
> src='editimage.jpg'>" UpdateText="<img src='updateimage.gif'>">
> </asp:EditCommandColumn>
> <asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
> Text="<img src='delete.gif'"></asp:ButtonColumn>
> </Columns>
> </asp:DataGrid>
> <asp:ImageButton ImageUrl="image.gif" id="btn_new"
> runat="server"></asp:ImageButton>
>
> This is the codebehind file update method :
> protected void Update (object sender, DataGridCommandEventArgs e)
> {
> DropDownList outlet = (DropDownList)e.Item.Cells[0].FindControl
> ("ddlOutlet");
> TextBox remarks = ((TextBox)e.Item.Cells[1].FindControl
> ("txtRemarks"));
> DataRow dr = dt.Rows[e.Item.DataSetIndex];
> dr["Outlet"] = outlet.SelectedItem.Text;
> dr["Remarks"] = remarks.Text;
> saveData();
> participateGrid.EditItemIndex = -1;
> BindGrid();
> }
> private void saveData ()
> {
> //stores the information in a viewstate
> ViewState ["Participate"] = dt;
> }
> //bind the data
> private void BindGrid()
> {
> participateGrid.DataSource = dv;
> participateGrid.DataBind();
> }
Below is my page load event. I suspect something is wrong with the
loadData method, is it?
private void Page_Load(object sender, System.EventArgs e)
{
if (ViewState ["Participate"] == null)
{
loadData();
ViewState["Participate"] = dt;
}
else
{
dt = (DataTable)ViewState["Participate"];
dv = new DataView (dt);
}
if (!IsPostBack)
{
Session ["ParticipateCounter"] = gridCounter;
}
else
{
gridCounter = (int)Session ["ParticipateCounter"];
}
BindGrid();
}
//page load event
//initialise the local objects
private void loadData ()
{
dt = new DataTable();
dt.Columns.Add (new DataColumn ("Outlet", typeof(string)));
dt.Columns.Add (new DataColumn ("Remarks", typeof(string)));
dv = new DataView(dt);
}
As I said, put BindGrid method into if (!IsPostBack)
--
Thanks,
Yunus Emre ALPZEN
"yew chong" <ycquak@.gmail.com> wrote in message
news:1107505653.693376.107750@.z14g2000cwz.googlegr oups.com...
> Below is my page load event. I suspect something is wrong with the
> loadData method, is it?
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (ViewState ["Participate"] == null)
> {
> loadData();
> ViewState["Participate"] = dt;
> }
> else
> {
> dt = (DataTable)ViewState["Participate"];
> dv = new DataView (dt);
> }
> if (!IsPostBack)
> {
> Session ["ParticipateCounter"] = gridCounter;
> }
> else
> {
> gridCounter = (int)Session ["ParticipateCounter"];
> }
> BindGrid();
> }
> //page load event
> //initialise the local objects
> private void loadData ()
> {
> dt = new DataTable();
> dt.Columns.Add (new DataColumn ("Outlet", typeof(string)));
> dt.Columns.Add (new DataColumn ("Remarks", typeof(string)));
> dv = new DataView(dt);
> }
yep, got it! Thanks! Managed to get the right values.
Hmm, maybe would just like to ask another question. Why is it that when
I click on update, after posting back, I still get the edit box?
I have set my EditItemIndex to -1 already. Why is it not being set to
-1? Thanks!
Regards
Yew Chong
Surely it caused by event order. Everytime event order is as follows.
1. Page_Load
2. Click events
3. Changed events
Every time the page is posted client. Firstly your datagrid is binded then
events like datagrid events are handled. So edit item index is set after the
datagrid is binded.
--
Thanks,
Yunus Emre ALPZEN
"yew chong" <ycquak@.gmail.com> wrote in message
news:1107571021.594077.69610@.l41g2000cwc.googlegro ups.com...
> yep, got it! Thanks! Managed to get the right values.
> Hmm, maybe would just like to ask another question. Why is it that when
> I click on update, after posting back, I still get the edit box?
> I have set my EditItemIndex to -1 already. Why is it not being set to
> -1? Thanks!
> Regards
> Yew Chong
Thanks a lot! I got this working as well.
Really thanks for the time taken to answer my questions.
Newbie : Updating problem with Datagrid
I have a page with a datagrid control. What I would like to do is when
I click on the update statement, I will update to the datagrid. However
the problem I am facing currently is when I click on update, the value
which I got from the controls generated by the datagrid edit template
is empty. Is there something I am missing out on? I have attached the
source codes below, please advice. Thanks!
Web User Control :
<asp:DataGrid id="participateGrid" runat="server"
AutoGenerateColumns="False" CellPadding="1" CellSpacing="1"
Width="100%" BorderColor="White" BorderStyle="None"
OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
ShowHeader="True">
<HeaderStyle BackColor="#dedfde" CssClass="tableLabel"></HeaderStyle>
<ItemStyle CssClass="tableItem" BackColor="#f7e7e7"></ItemStyle>
<Columns>
<asp:TemplateColumn HeaderText="Outlet">
<EditItemTemplate>
<asp:DropDownList ID="ddlOutlet" Runat="server">
<asp:ListItem>...</asp:ListItem>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Remarks">
<EditItemTemplate>
<asp:TextBox id="txtRemarks" TextMode="MultiLine" Rows="2"
Columns="15" Runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" EditText="<img
src='editimage.jpg'>" UpdateText="<img src='updateimage.gif'>">
</asp:EditCommandColumn>
<asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
Text="<img src='delete.gif'"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
<asp:ImageButton ImageUrl="image.gif" id="btn_new"
runat="server"></asp:ImageButton>
This is the codebehind file update method :
protected void Update (object sender, DataGridCommandEventArgs e)
{
DropDownList outlet = (DropDownList)e.Item.Cells[0].FindControl
("ddlOutlet");
TextBox remarks = ((TextBox)e.Item.Cells[1].FindControl
("txtRemarks"));
DataRow dr = dt.Rows[e.Item.DataSetIndex];
dr["Outlet"] = outlet.SelectedItem.Text;
dr["Remarks"] = remarks.Text;
saveData();
participateGrid.EditItemIndex = -1;
BindGrid();
}
private void saveData ()
{
//stores the information in a viewstate
ViewState ["Participate"] = dt;
}
//bind the data
private void BindGrid()
{
participateGrid.DataSource = dv;
participateGrid.DataBind();
}Are u binding your datagrid on page load? Page load event occurs before
datagrid update event.
If your answer is yes, control postback on your page load something like
this:
if (!IsPostBack)
{
BindGrid();
}
Thanks,
Yunus Emre ALPZEN
<ycquak@.gmail.com> wrote in message
news:1107496691.787654.33590@.c13g2000cwb.googlegroups.com...
> Hi,
> I have a page with a datagrid control. What I would like to do is when
> I click on the update statement, I will update to the datagrid. However
> the problem I am facing currently is when I click on update, the value
> which I got from the controls generated by the datagrid edit template
> is empty. Is there something I am missing out on? I have attached the
> source codes below, please advice. Thanks!
> Web User Control :
> <asp:DataGrid id="participateGrid" runat="server"
> AutoGenerateColumns="False" CellPadding="1" CellSpacing="1"
> Width="100%" BorderColor="White" BorderStyle="None"
> OnEditCommand="Edit" OnDeleteCommand="Delete" OnUpdateCommand="Update"
> ShowHeader="True">
> <HeaderStyle BackColor="#dedfde" CssClass="tableLabel"></HeaderStyle>
> <ItemStyle CssClass="tableItem" BackColor="#f7e7e7"></ItemStyle>
> <Columns>
> <asp:TemplateColumn HeaderText="Outlet">
> <EditItemTemplate>
> <asp:DropDownList ID="ddlOutlet" Runat="server">
> <asp:ListItem>...</asp:ListItem>
> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn HeaderText="Remarks">
> <EditItemTemplate>
> <asp:TextBox id="txtRemarks" TextMode="MultiLine" Rows="2"
> Columns="15" Runat="server"></asp:TextBox>
> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:EditCommandColumn ButtonType="LinkButton" EditText="<img
> src='editimage.jpg'>" UpdateText="<img src='updateimage.gif'>">
> </asp:EditCommandColumn>
> <asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton"
> Text="<img src='delete.gif'"></asp:ButtonColumn>
> </Columns>
> </asp:DataGrid>
> <asp:ImageButton ImageUrl="image.gif" id="btn_new"
> runat="server"></asp:ImageButton>
>
> This is the codebehind file update method :
> protected void Update (object sender, DataGridCommandEventArgs e)
> {
> DropDownList outlet = (DropDownList)e.Item.Cells[0].FindControl
> ("ddlOutlet");
> TextBox remarks = ((TextBox)e.Item.Cells[1].FindControl
> ("txtRemarks"));
> DataRow dr = dt.Rows[e.Item.DataSetIndex];
> dr["Outlet"] = outlet.SelectedItem.Text;
> dr["Remarks"] = remarks.Text;
> saveData();
> participateGrid.EditItemIndex = -1;
> BindGrid();
> }
> private void saveData ()
> {
> //stores the information in a viewstate
> ViewState ["Participate"] = dt;
> }
> //bind the data
> private void BindGrid()
> {
> participateGrid.DataSource = dv;
> participateGrid.DataBind();
> }
>
Below is my page load event. I suspect something is wrong with the
loadData method, is it?
private void Page_Load(object sender, System.EventArgs e)
{
if (ViewState ["Participate"] == null)
{
loadData();
ViewState["Participate"] = dt;
}
else
{
dt = (DataTable)ViewState["Participate"];
dv = new DataView (dt);
}
if (!IsPostBack)
{
Session ["ParticipateCounter"] = gridCounter;
}
else
{
gridCounter = (int)Session ["ParticipateCounter"];
}
BindGrid();
}
//page load event
//initialise the local objects
private void loadData ()
{
dt = new DataTable();
dt.Columns.Add (new DataColumn ("Outlet", typeof(string)));
dt.Columns.Add (new DataColumn ("Remarks", typeof(string)));
dv = new DataView(dt);
}
As I said, put BindGrid method into if (!IsPostBack)
Thanks,
Yunus Emre ALPZEN
"yew chong" <ycquak@.gmail.com> wrote in message
news:1107505653.693376.107750@.z14g2000cwz.googlegroups.com...
> Below is my page load event. I suspect something is wrong with the
> loadData method, is it?
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (ViewState ["Participate"] == null)
> {
> loadData();
> ViewState["Participate"] = dt;
> }
> else
> {
> dt = (DataTable)ViewState["Participate"];
> dv = new DataView (dt);
> }
> if (!IsPostBack)
> {
> Session ["ParticipateCounter"] = gridCounter;
> }
> else
> {
> gridCounter = (int)Session ["ParticipateCounter"];
> }
> BindGrid();
> }
> //page load event
> //initialise the local objects
> private void loadData ()
> {
> dt = new DataTable();
> dt.Columns.Add (new DataColumn ("Outlet", typeof(string)));
> dt.Columns.Add (new DataColumn ("Remarks", typeof(string)));
> dv = new DataView(dt);
> }
>
yep, got it! Thanks! Managed to get the right values.
Hmm, maybe would just like to ask another question. Why is it that when
I click on update, after posting back, I still get the edit box?
I have set my EditItemIndex to -1 already. Why is it not being set to
-1? Thanks!
Regards
Yew Chong
Surely it caused by event order. Everytime event order is as follows.
1. Page_Load
2. Click events
3. Changed events
Every time the page is posted client. Firstly your datagrid is binded then
events like datagrid events are handled. So edit item index is set after the
datagrid is binded.
--
Thanks,
Yunus Emre ALPZEN
"yew chong" <ycquak@.gmail.com> wrote in message
news:1107571021.594077.69610@.l41g2000cwc.googlegroups.com...
> yep, got it! Thanks! Managed to get the right values.
> Hmm, maybe would just like to ask another question. Why is it that when
> I click on update, after posting back, I still get the edit box?
> I have set my EditItemIndex to -1 already. Why is it not being set to
> -1? Thanks!
> Regards
> Yew Chong
>
Thanks a lot! I got this working as well.
Really thanks for the time taken to answer my questions.
Newbie ? - Error on Redirect from login page error
Trying to make a login page to a website. However I don't the user to be
able to set a password, I want to control the password for everbody, and
change it w
to be used as a login page. But they all are a little diffrent, and always
cover the highlights. I would love to see something that takes me from poin
t
A to Point B. Anyway's, I have been making some progress, although slower
than I would like. So here is a snippet of my code for my login button.
Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogIn.Click
' Server.Transfer("main.aspx") used to go to main page
Session("User Name") = txtUN.Text
Session("Password") = txtPW.Text
FormsAuthentication.RedirectFromLoginPage(txtUN.Text, False)
End Sub
And here is my web config code
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<location path="ProtectMe.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location>
<system.web>
<httpHandlers>
<add verb="*" path="Users.xml"
type="System.Web.HttpForbiddenHandler"/>
</httpHandlers>
<authentication mode="Forms">
<forms name="ImsApp"
loginUrl="localhost/mmgims/Login1.aspx" protection="all"/>
</forms>
</authentication>
</system.web>
</configuration>
It is my understanding that the redirectfromloginpage should take me to the
login page if the password or User name is wrong. But this is what I get for
an error
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make sure that
it is spelled correctly.
Requested Url: /mmgims/default.aspx
I don't have a default page, I have the login page, and the main page which
would be my home page. Again, I been taking a little bit of info from
everywhaere.
Any advise would be great!!!
Thanks to all!!!
RudyI think your problem is the loginUrl in your web.config.
Make this path relative to the web.config
so your web.config is under the root, and your login page is under
mmgims directory make it this:
loginUrl="mmgims/Login1.aspx"
leave the localhost part out of there. your page is redirecting how it
should, but it can't find the login page you specified.
let me know if that works.
DKode
Thanks for the tip, that does make sense! I'll try it out tonite and let you
know.
Rudy
"DKode" wrote:
> I think your problem is the loginUrl in your web.config.
> Make this path relative to the web.config
> so your web.config is under the root, and your login page is under
> mmgims directory make it this:
> loginUrl="mmgims/Login1.aspx"
> leave the localhost part out of there. your page is redirecting how it
> should, but it can't find the login page you specified.
> let me know if that works.
> DKode
>
thanks DKode, that did the trick!
"Rudy" wrote:
> Thanks for the tip, that does make sense! I'll try it out tonite and let y
ou
> know.
> Rudy
> "DKode" wrote:
>
Newbie ? - Error on Redirect from login page error
Trying to make a login page to a website. However I don't the user to be
able to set a password, I want to control the password for everbody, and
change it weekly. Any way, I have found alot of docs on Form Authentication
to be used as a login page. But they all are a little diffrent, and always
cover the highlights. I would love to see something that takes me from point
A to Point B. Anyway's, I have been making some progress, although slower
than I would like. So here is a snippet of my code for my login button.
Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnLogIn.Click
' Server.Transfer("main.aspx") used to go to main page
Session("User Name") = txtUN.Text
Session("Password") = txtPW.Text
FormsAuthentication.RedirectFromLoginPage(txtUN.Te xt, False)
End Sub
And here is my web config code
<?xml version="1.0" encoding="utf-8" ?>
<configuration
<location path="ProtectMe.aspx">
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
</location
<system.web
<httpHandlers>
<add verb="*" path="Users.xml"
type="System.Web.HttpForbiddenHandler"/>
</httpHandlers
<authentication mode="Forms">
<forms name="ImsApp"
loginUrl="localhost/mmgims/Login1.aspx" protection="all"/
</forms>
</authentication
</system.web>
</configuration>
It is my understanding that the redirectfromloginpage should take me to the
login page if the password or User name is wrong. But this is what I get for
an error
Description: HTTP 404. The resource you are looking for (or one of its
dependencies) could have been removed, had its name changed, or is
temporarily unavailable. Please review the following URL and make sure that
it is spelled correctly.
Requested Url: /mmgims/default.aspx
I don't have a default page, I have the login page, and the main page which
would be my home page. Again, I been taking a little bit of info from
everywhaere.
Any advise would be great!!!
Thanks to all!!!
RudyI think your problem is the loginUrl in your web.config.
Make this path relative to the web.config
so your web.config is under the root, and your login page is under
mmgims directory make it this:
loginUrl="mmgims/Login1.aspx"
leave the localhost part out of there. your page is redirecting how it
should, but it can't find the login page you specified.
let me know if that works.
DKode
Thanks for the tip, that does make sense! I'll try it out tonite and let you
know.
Rudy
"DKode" wrote:
> I think your problem is the loginUrl in your web.config.
> Make this path relative to the web.config
> so your web.config is under the root, and your login page is under
> mmgims directory make it this:
> loginUrl="mmgims/Login1.aspx"
> leave the localhost part out of there. your page is redirecting how it
> should, but it can't find the login page you specified.
> let me know if that works.
> DKode
>
thanks DKode, that did the trick!
"Rudy" wrote:
> Thanks for the tip, that does make sense! I'll try it out tonite and let you
> know.
> Rudy
> "DKode" wrote:
> > I think your problem is the loginUrl in your web.config.
> > Make this path relative to the web.config
> > so your web.config is under the root, and your login page is under
> > mmgims directory make it this:
> > loginUrl="mmgims/Login1.aspx"
> > leave the localhost part out of there. your page is redirecting how it
> > should, but it can't find the login page you specified.
> > let me know if that works.
> > DKode
Newbie Alert: Please help with repeater control and list box
I am new to asp.net!
I can create a repeater control but would like to add a select list to
it as follows:
<%@dotnet.itags.org. Page Language="vb" debug=true %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<script runat="server"
Sub Page_Load(sender As Object, e As EventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
myConnection = New SqlConnection("server=local;user
id=whocares;database=dbSeekersClientApp;Trusted_Co nnection=false")
myCommand = New SqlDataAdapter("SELECT ID, username, password,
firstname, surname, account_live FROM t_managers", myConnection)
Dim ds As Dataset = new DataSet()
myCommand.Fill(ds)
MyRepeater.DataSource = ds
MyRepeater.DataBind()
End SUb
</script>
<html>
<head>
</head>
<body
<form action="intro1.aspx" method="post" runat="server"
<ASP:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="background-color:DFA894">
<th>
User ID
</th>
<th>
Surname
</th>
<th>
Firstname
</th>
<th>
Username
</th>
<th>
Password
</th>
<th>
Access
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FFECD8">
<td>
<%# DataBinder.Eval(Container.DataItem, "ID") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "surname")
%>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"firstname") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"username") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"password") %>
</td>
<td>
>>>>> Problem code
<asp:DropDownList id="dList1" width=100 runat="server">
<option
value=<%#DataBinder.Eval(Container.DataItem, "account_live")%>>
<%# DataBinder.Eval(Container.DataItem, "account_live") %>
</option>
>>>> Problem code ends
</asp:DropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</ASP:Repeater>
</form>
</body>
</html
Any pointers?Your post went unanswered. Have you resolved this issue?
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"John sorCrer" <info@.emap.co.za> wrote in message
news:d70138e4.0403021226.36b59c74@.posting.google.c om...
> Hi Guru's,
> I am new to asp.net!
> I can create a repeater control but would like to add a select list to
> it as follows:
> <%@. Page Language="vb" debug=true %>
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> <script runat="server">
> Sub Page_Load(sender As Object, e As EventArgs)
> Dim myConnection As SqlConnection
> Dim myCommand As SqlDataAdapter
> myConnection = New SqlConnection("server=local;user
> id=whocares;database=dbSeekersClientApp;Trusted_Co nnection=false")
> myCommand = New SqlDataAdapter("SELECT ID, username, password,
> firstname, surname, account_live FROM t_managers", myConnection)
> Dim ds As Dataset = new DataSet()
> myCommand.Fill(ds)
> MyRepeater.DataSource = ds
> MyRepeater.DataBind()
> End SUb
> </script>
> <html>
> <head>
> </head>
> <body>
> <form action="intro1.aspx" method="post" runat="server">
> <ASP:Repeater id="MyRepeater" runat="server">
> <HeaderTemplate>
> <table width="100%" style="font: 8pt verdana">
> <tr style="background-color:DFA894">
> <th>
> User ID
> </th>
> <th>
> Surname
> </th>
> <th>
> Firstname
> </th>
> <th>
> Username
> </th>
> <th>
> Password
> </th>
> <th>
> Access
> </th>
> </tr>
> </HeaderTemplate>
> <ItemTemplate>
> <tr style="background-color:FFECD8">
> <td>
> <%# DataBinder.Eval(Container.DataItem, "ID") %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem, "surname")
> %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem,
> "firstname") %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem,
> "username") %>
> </td>
> <td>
> <%# DataBinder.Eval(Container.DataItem,
> "password") %>
> </td>
> <td>
> >>>>> Problem code
> <asp:DropDownList id="dList1" width=100 runat="server">
> <option
> value=<%#DataBinder.Eval(Container.DataItem, "account_live")%>>
> <%# DataBinder.Eval(Container.DataItem, "account_live") %>
> </option>
> >>>> Problem code ends
> </asp:DropDownList>
> </td>
> </tr>
> </ItemTemplate>
> <FooterTemplate>
> </table>
> </FooterTemplate>
> </ASP:Repeater>
> </form>
> </body>
> </html>
>
> Any pointers?
newbie asp.net user control question
an .ascx extension. I use this control many times within this
application and it works fine. I wrote this user control to be
generic though, because I want it to be accessible from other asp.net
applications as well. How do I break out the user control into a
seperate dll that can be references by many asp.net apps? I fooled
around with the "Web Control Library" but I must be doing something
wrong because it doesn't seem right. For instance it is listing a
"Windows Forms" section on the toolbox rather than the "Web Forms"
section that I need. Also there is no html section on the designer.
I must have gone off track somewhere... Any help you can provide
would be greatly appreciated. Thanks!On Jun 27, 10:55 pm, mbosc...@.hotmail.com wrote:
> Hi, I created a user control within my asp.net application. It has
> an .ascx extension. I use this control many times within this
> application and it works fine. I wrote this user control to be
> generic though, because I want it to be accessible from other asp.net
> applications as well. How do I break out the user control into a
> seperate dll that can be references by many asp.net apps? I fooled
> around with the "Web Control Library" but I must be doing something
> wrong because it doesn't seem right. For instance it is listing a
> "Windows Forms" section on the toolbox rather than the "Web Forms"
> section that I need. Also there is no html section on the designer.
> I must have gone off track somewhere... Any help you can provide
> would be greatly appreciated. Thanks!
hi... :)
If you want to use your control in multiple projects and you actually
want made it generic enough you have to write a custom control... okay
that good... now you can still use user user control in multiple
project but for this you got to copy the ascx file and its cs file to
the new project...
Thanks
Masudur
http://www.kaz.com.bd
http://munnacs.110mb.com
newbie asp.net user control question
an .ascx extension. I use this control many times within this
application and it works fine. I wrote this user control to be
generic though, because I want it to be accessible from other asp.net
applications as well. How do I break out the user control into a
seperate dll that can be references by many asp.net apps? I fooled
around with the "Web Control Library" but I must be doing something
wrong because it doesn't seem right. For instance it is listing a
"Windows Forms" section on the toolbox rather than the "Web Forms"
section that I need. Also there is no html section on the designer.
I must have gone off track somewhere... Any help you can provide
would be greatly appreciated. Thanks!On Jun 27, 10:55 pm, mbosc...@.hotmail.com wrote:
Quote:
Originally Posted by
Hi, I created a user control within my asp.net application. It has
an .ascx extension. I use this control many times within this
application and it works fine. I wrote this user control to be
generic though, because I want it to be accessible from other asp.net
applications as well. How do I break out the user control into a
seperate dll that can be references by many asp.net apps? I fooled
around with the "Web Control Library" but I must be doing something
wrong because it doesn't seem right. For instance it is listing a
"Windows Forms" section on the toolbox rather than the "Web Forms"
section that I need. Also there is no html section on the designer.
I must have gone off track somewhere... Any help you can provide
would be greatly appreciated. Thanks!
hi... :)
If you want to use your control in multiple projects and you actually
want made it generic enough you have to write a custom control... okay
that good... now you can still use user user control in multiple
project but for this you got to copy the ascx file and its cs file to
the new project...
Thanks
Masudur
http://www.kaz.com.bd
http://munnacs.110mb.com
Saturday, March 24, 2012
Newbie Embedded WUC DLL Question
I've been racking my brains trying to figure out what's going on with
my embedded .NET 2.0 windows user control.
I've developed a Windows Forms application using Visual C# 2005
Express. I'm interested in migrating it to the web as an embedded
windows user control.
As a proof of concept, I've been playing around embedding some very
basic Windows user controls into both HTML and ASP pages using Visual
Web Developer 2005 Express. (My web development is very limited).
I've done some searching and found examples of how to embed a user
control as an object by inserting something like the following
(<OBJECT id="myObject" classid="myDll.dll#myNamespace.myControl"
height=480 width=480></OBJECT> ) into HTML code and copying the DLL
file in the 'root' (not /bin) directory of the page.
Now here's where the fun comes in...
I'm testing some very basic embedded controls using Microsoft's
ASP.NET Development server and I'm getting some very odd and
unexplained behavior.
1) When I create a new website project and insert the control, most of
the time (but not always) my sample control will display in the
internal browser inside the Visual Web Developer IDE and it will
display in IE (as launched from the Visual Web Developer IDE in debug
mode)
2) If I change the embedded user control code (inside Visual C#
Express) and recompile and re-copy the DLL file into the web project
directory, I very rarely see the updates reflected in the user
control. It seems to be using a cached version of the DLL'
3) Eventually, I will reach a state where the user control no longer
even appears in the web browser window when trying to run the site
(using the Development Server). It only shows up as an object icon
place holder.
I've tried all sorts of things like:
1) Stopping the development server before copying the new DLL file
into the web project
2) Restarting Visual Web Developer Express
3) Deleting all the temporary IE files
4) Deleting all the files from C:\WINDOWS\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files\
None of those attempts seems to change what I'm observing - why only
sometimes the embedded control displays and why none of the re-
compiles/re-copying of the DLL files seem to 'take effect'. Also,
once the control stops displaying, I essentially have to create an
entirely new web project to see the control again.
Any thoughts/links to examples or suggestions would be greatly
appreciated.
Thanks,
Mike D.the control is cached in two places
1) ie caches the dll in its temp area (use delete temp files in ie).
2) the gac caches the jit'd code. use gacutil /cdl
note: this is probably a dead-end approach. you should look at
Silverlight as a more long term solution.
-- bruce (sqlwork.com)
mdemase@.gmail.com wrote:
> Hello -
> I've been racking my brains trying to figure out what's going on with
> my embedded .NET 2.0 windows user control.
> I've developed a Windows Forms application using Visual C# 2005
> Express. I'm interested in migrating it to the web as an embedded
> windows user control.
> As a proof of concept, I've been playing around embedding some very
> basic Windows user controls into both HTML and ASP pages using Visual
> Web Developer 2005 Express. (My web development is very limited).
> I've done some searching and found examples of how to embed a user
> control as an object by inserting something like the following
> (<OBJECT id="myObject" classid="myDll.dll#myNamespace.myControl"
> height=480 width=480></OBJECT> ) into HTML code and copying the DLL
> file in the 'root' (not /bin) directory of the page.
> Now here's where the fun comes in...
> I'm testing some very basic embedded controls using Microsoft's
> ASP.NET Development server and I'm getting some very odd and
> unexplained behavior.
> 1) When I create a new website project and insert the control, most of
> the time (but not always) my sample control will display in the
> internal browser inside the Visual Web Developer IDE and it will
> display in IE (as launched from the Visual Web Developer IDE in debug
> mode)
> 2) If I change the embedded user control code (inside Visual C#
> Express) and recompile and re-copy the DLL file into the web project
> directory, I very rarely see the updates reflected in the user
> control. It seems to be using a cached version of the DLL'
> 3) Eventually, I will reach a state where the user control no longer
> even appears in the web browser window when trying to run the site
> (using the Development Server). It only shows up as an object icon
> place holder.
> I've tried all sorts of things like:
> 1) Stopping the development server before copying the new DLL file
> into the web project
> 2) Restarting Visual Web Developer Express
> 3) Deleting all the temporary IE files
> 4) Deleting all the files from C:\WINDOWS\Microsoft.NET\Framework
> \v2.0.50727\Temporary ASP.NET Files\
> None of those attempts seems to change what I'm observing - why only
> sometimes the embedded control displays and why none of the re-
> compiles/re-copying of the DLL files seem to 'take effect'. Also,
> once the control stops displaying, I essentially have to create an
> entirely new web project to see the control again.
> Any thoughts/links to examples or suggestions would be greatly
> appreciated.
> Thanks,
> Mike D.
>
Newbie Embedded WUC DLL Question
I've been racking my brains trying to figure out what's going on with
my embedded .NET 2.0 windows user control.
I've developed a Windows Forms application using Visual C# 2005
Express. I'm interested in migrating it to the web as an embedded
windows user control.
As a proof of concept, I've been playing around embedding some very
basic Windows user controls into both HTML and ASP pages using Visual
Web Developer 2005 Express. (My web development is very limited).
I've done some searching and found examples of how to embed a user
control as an object by inserting something like the following
(<OBJECT id="myObject" classid="myDll.dll#myNamespace.myControl"
height=480 width=480></OBJECT>) into HTML code and copying the DLL
file in the 'root' (not /bin) directory of the page.
Now here's where the fun comes in...
I'm testing some very basic embedded controls using Microsoft's
ASP.NET Development server and I'm getting some very odd and
unexplained behavior.
1) When I create a new website project and insert the control, most of
the time (but not always) my sample control will display in the
internal browser inside the Visual Web Developer IDE and it will
display in IE (as launched from the Visual Web Developer IDE in debug
mode)
2) If I change the embedded user control code (inside Visual C#
Express) and recompile and re-copy the DLL file into the web project
directory, I very rarely see the updates reflected in the user
control. It seems to be using a cached version of the DLL??
3) Eventually, I will reach a state where the user control no longer
even appears in the web browser window when trying to run the site
(using the Development Server). It only shows up as an object icon
place holder.
I've tried all sorts of things like:
1) Stopping the development server before copying the new DLL file
into the web project
2) Restarting Visual Web Developer Express
3) Deleting all the temporary IE files
4) Deleting all the files from C:\WINDOWS\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files\
None of those attempts seems to change what I'm observing - why only
sometimes the embedded control displays and why none of the re-
compiles/re-copying of the DLL files seem to 'take effect'. Also,
once the control stops displaying, I essentially have to create an
entirely new web project to see the control again.
Any thoughts/links to examples or suggestions would be greatly
appreciated.
Thanks,
Mike D.the control is cached in two places
1) ie caches the dll in its temp area (use delete temp files in ie).
2) the gac caches the jit'd code. use gacutil /cdl
note: this is probably a dead-end approach. you should look at
Silverlight as a more long term solution.
-- bruce (sqlwork.com)
mdemase@.gmail.com wrote:
Quote:
Originally Posted by
Hello -
>
I've been racking my brains trying to figure out what's going on with
my embedded .NET 2.0 windows user control.
>
I've developed a Windows Forms application using Visual C# 2005
Express. I'm interested in migrating it to the web as an embedded
windows user control.
>
As a proof of concept, I've been playing around embedding some very
basic Windows user controls into both HTML and ASP pages using Visual
Web Developer 2005 Express. (My web development is very limited).
I've done some searching and found examples of how to embed a user
control as an object by inserting something like the following
(<OBJECT id="myObject" classid="myDll.dll#myNamespace.myControl"
height=480 width=480></OBJECT>) into HTML code and copying the DLL
file in the 'root' (not /bin) directory of the page.
>
Now here's where the fun comes in...
>
I'm testing some very basic embedded controls using Microsoft's
ASP.NET Development server and I'm getting some very odd and
unexplained behavior.
>
1) When I create a new website project and insert the control, most of
the time (but not always) my sample control will display in the
internal browser inside the Visual Web Developer IDE and it will
display in IE (as launched from the Visual Web Developer IDE in debug
mode)
>
2) If I change the embedded user control code (inside Visual C#
Express) and recompile and re-copy the DLL file into the web project
directory, I very rarely see the updates reflected in the user
control. It seems to be using a cached version of the DLL??
>
3) Eventually, I will reach a state where the user control no longer
even appears in the web browser window when trying to run the site
(using the Development Server). It only shows up as an object icon
place holder.
>
I've tried all sorts of things like:
1) Stopping the development server before copying the new DLL file
into the web project
2) Restarting Visual Web Developer Express
3) Deleting all the temporary IE files
4) Deleting all the files from C:\WINDOWS\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files\
>
None of those attempts seems to change what I'm observing - why only
sometimes the embedded control displays and why none of the re-
compiles/re-copying of the DLL files seem to 'take effect'. Also,
once the control stops displaying, I essentially have to create an
entirely new web project to see the control again.
>
Any thoughts/links to examples or suggestions would be greatly
appreciated.
>
Thanks,
Mike D.
>
Thursday, March 22, 2012
newbie in asp.net need help
I have a asp:listbox control. I want to have a javascript function that
detect the onselectedindexchanged and then make another textbox visible.
It just like the old fashion way in asp <select onchanged="myfunction()" >.
But with asp.net control i can't do that anymore on client-side
Please help ...Yes, you can.
myListBox.Attributes["onchanged"]="myfunction()";
Eliyahu
"hoaian" <hoaian@.yahoo.com> wrote in message
news:uA3mP8JWGHA.1084@.TK2MSFTNGP04.phx.gbl...
> Hi everyone,
> I have a asp:listbox control. I want to have a javascript function that
> detect the onselectedindexchanged and then make another textbox visible.
> It just like the old fashion way in asp <select onchanged="myfunction()"
> Please help ...
>
>
newbie in asp.net need help
I have a asp:listbox control. I want to have a javascript function that
detect the onselectedindexchanged and then make another textbox visible.
It just like the old fashion way in asp <select onchanged="myfunction()" >.
But with asp.net control i can't do that anymore on client-side
Please help ...Yes, you can.
myListBox.Attributes["onchanged"]="myfunction()";
Eliyahu
"hoaian" <hoaian@.yahoo.com> wrote in message
news:uA3mP8JWGHA.1084@.TK2MSFTNGP04.phx.gbl...
> Hi everyone,
> I have a asp:listbox control. I want to have a javascript function that
> detect the onselectedindexchanged and then make another textbox visible.
> It just like the old fashion way in asp <select onchanged="myfunction()"
> >. But with asp.net control i can't do that anymore on client-side
> Please help ...
>
Newbie mistake or Custom Validator bug?
We have created a custom control. The control includes an ordinary textbox,
a customvalidator with the ControlToValidate set to the textbox, and a
VBScript validator subroutine. The purpose of the sub is to insure that only
dates that fall on Monday are permitted. The custom validator is exposed
through a property to permit enabling and disabling as needed.
The problem is this. If I have two instances of the control on a page, the
custom validator of the first instance is apparently calling the sub of the
second. The net effect is that I cannot properly validate Mondays on the
first control. This control seems to work fine when there is only one
instance on a page. When I examine the HTML source, it appears that there
are the correct instances of the code, each accessing the correct controls.
(I should admit upfront that the control also contains a ThirdParty calendar
date selector, Telerik, but as far as I can tell, none of the problem code
interacts with it in any way. It's sole purpose is to put a property
formatted date string into the textbox.)Please post:
1. The ASP.NET definitions of the controls involved.
2. The server side code involved.
3. The client-side code involved.
-- Peter Blum
www.PeterBlum.com
Email: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"B. Chernick" <BChernick@.discussions.microsoft.com> wrote in message
news:4AC9AE8B-E970-4340-AAD3-EB49500ED8A0@.microsoft.com...
>I have a very strange problem involving controls and the CustomValidator.
> We have created a custom control. The control includes an ordinary
> textbox,
> a customvalidator with the ControlToValidate set to the textbox, and a
> VBScript validator subroutine. The purpose of the sub is to insure that
> only
> dates that fall on Monday are permitted. The custom validator is exposed
> through a property to permit enabling and disabling as needed.
> The problem is this. If I have two instances of the control on a page,
> the
> custom validator of the first instance is apparently calling the sub of
> the
> second. The net effect is that I cannot properly validate Mondays on the
> first control. This control seems to work fine when there is only one
> instance on a page. When I examine the HTML source, it appears that there
> are the correct instances of the code, each accessing the correct
> controls.
> (I should admit upfront that the control also contains a ThirdParty
> calendar
> date selector, Telerik, but as far as I can tell, none of the problem code
> interacts with it in any way. It's sole purpose is to put a property
> formatted date string into the textbox.)
I have just created a test case (without any 3rd party controls,
incidentally. That appears to have nothing to do with the problem)
First create a user control with a textbox and a custom validator:
-- ASPX starts here -----
<%@. Control Language="vb" AutoEventWireup="false"
Codebehind="CalendarTest.ascx.vb" Inherits="test1.CalendarTest"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:TextBox id="txtDate" runat="server" Columns="18"
CssClass="text"></asp:TextBox>
<asp:CustomValidator id="MondayValidator1" runat="server"
ClientValidationFunction="ValidateMondayVB"
ErrorMessage="The Date is not a Monday" Enabled="False"
ControlToValidate="txtDate">*</asp:CustomValidator>
<script language="vbscript"
Sub ValidateMondayVB(source, args)
If IsDate(document.forms("Form1").item("<%= Me.txtDate.ClientID
%>").Value) then
startDt = CDate(document.forms("Form1").item("<%= Me.txtDate.ClientID
%>").Value)
msgbox "Here I am control <%= Me.ClientID %>, box = <%=
Me.txtDate.ClientID %> , source.id = " & source.id
If WeekDay(startDt) <> vbMonday then
msgbox "Start date must be a Monday. You specified a " &
WeekdayName(WeekDay(startDt)) & "."
args.IsValid = false
Else
args.IsValid = true
End if
End if
End Sub
</script
--- ASPX ends here ----
Next add the following property to the control code behind:
Public Property MondayValidator() As CustomValidator
Get
Return MondayValidator1
End Get
Set(ByVal Value As CustomValidator)
MondayValidator1 = Value
End Set
End Property
---
Now create a test page using the control:
--- test page ASPX starts here ----------
<%@. Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm12.aspx.vb" Inherits="test1.WebForm12"%>
<%@. Register TagPrefix="uc1" TagName="CalendarTest" src="http://pics.10026.com/?src=CalendarTest.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm12</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:ValidationSummary id="ValidationSummary1" runat="server"
BorderStyle="Outset" Width="272px"></asp:ValidationSummary>
<P>
<uc1:CalendarTest id="CalendarTest1"
runat="server"></uc1:CalendarTest>
<uc1:CalendarTest id="CalendarTest2"
runat="server"></uc1:CalendarTest></P>
<P> </P>
<P>
<asp:Button id="Button1" runat="server" Text="Validate"></asp:Button></P>
</form>
</body>
</HTML>
--- test page ASPX ends here -------
Finally add the following to the test page's Page_Load
CalendarTest1.MondayValidator.Enabled = True
CalendarTest1.MondayValidator.ErrorMessage = "Test1 Fired"
CalendarTest2.MondayValidator.Enabled = False
CalendarTest2.MondayValidator.ErrorMessage = "Test2 Fired"
Now run the project. Enter a Monday date (2/20/2006 for example) in the
first box. Enter a non-Monday date in the second. (In my actual work, these
boxes would have Javascript formatting routines forcing a mm/dd/yyyy format
so only use that.) Now press the button. The first validator fires after
apparently using the 2nd instances VBscript sub, or so it looks to me.
Thanks
"Peter Blum" wrote:
> Please post:
> 1. The ASP.NET definitions of the controls involved.
> 2. The server side code involved.
> 3. The client-side code involved.
> -- Peter Blum
> www.PeterBlum.com
> Email: PLBlum@.PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
> "B. Chernick" <BChernick@.discussions.microsoft.com> wrote in message
> news:4AC9AE8B-E970-4340-AAD3-EB49500ED8A0@.microsoft.com...
> >I have a very strange problem involving controls and the CustomValidator.
> > We have created a custom control. The control includes an ordinary
> > textbox,
> > a customvalidator with the ControlToValidate set to the textbox, and a
> > VBScript validator subroutine. The purpose of the sub is to insure that
> > only
> > dates that fall on Monday are permitted. The custom validator is exposed
> > through a property to permit enabling and disabling as needed.
> > The problem is this. If I have two instances of the control on a page,
> > the
> > custom validator of the first instance is apparently calling the sub of
> > the
> > second. The net effect is that I cannot properly validate Mondays on the
> > first control. This control seems to work fine when there is only one
> > instance on a page. When I examine the HTML source, it appears that there
> > are the correct instances of the code, each accessing the correct
> > controls.
> > (I should admit upfront that the control also contains a ThirdParty
> > calendar
> > date selector, Telerik, but as far as I can tell, none of the problem code
> > interacts with it in any way. It's sole purpose is to put a property
> > formatted date string into the textbox.)
>
Newbie mistake or Custom Validator bug?
We have created a custom control. The control includes an ordinary textbox,
a customvalidator with the ControlToValidate set to the textbox, and a
VBScript validator subroutine. The purpose of the sub is to insure that onl
y
dates that fall on Monday are permitted. The custom validator is exposed
through a property to permit enabling and disabling as needed.
The problem is this. If I have two instances of the control on a page, the
custom validator of the first instance is apparently calling the sub of the
second. The net effect is that I cannot properly validate Mondays on the
first control. This control seems to work fine when there is only one
instance on a page. When I examine the HTML source, it appears that there
are the correct instances of the code, each accessing the correct controls.
(I should admit upfront that the control also contains a ThirdParty calendar
date selector, Telerik, but as far as I can tell, none of the problem code
interacts with it in any way. It's sole purpose is to put a property
formatted date string into the textbox.)Please post:
1. The ASP.NET definitions of the controls involved.
2. The server side code involved.
3. The client-side code involved.
-- Peter Blum
www.PeterBlum.com
Email: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"B. Chernick" <BChernick@.discussions.microsoft.com> wrote in message
news:4AC9AE8B-E970-4340-AAD3-EB49500ED8A0@.microsoft.com...
>I have a very strange problem involving controls and the CustomValidator.
> We have created a custom control. The control includes an ordinary
> textbox,
> a customvalidator with the ControlToValidate set to the textbox, and a
> VBScript validator subroutine. The purpose of the sub is to insure that
> only
> dates that fall on Monday are permitted. The custom validator is exposed
> through a property to permit enabling and disabling as needed.
> The problem is this. If I have two instances of the control on a page,
> the
> custom validator of the first instance is apparently calling the sub of
> the
> second. The net effect is that I cannot properly validate Mondays on the
> first control. This control seems to work fine when there is only one
> instance on a page. When I examine the HTML source, it appears that there
> are the correct instances of the code, each accessing the correct
> controls.
> (I should admit upfront that the control also contains a ThirdParty
> calendar
> date selector, Telerik, but as far as I can tell, none of the problem code
> interacts with it in any way. It's sole purpose is to put a property
> formatted date string into the textbox.)
>
I have just created a test case (without any 3rd party controls,
incidentally. That appears to have nothing to do with the problem)
First create a user control with a textbox and a custom validator:
-- ASPX starts here --
<%@. Control Language="vb" AutoEventWireup="false"
Codebehind="CalendarTest.ascx.vb" Inherits="test1.CalendarTest"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:TextBox id="txtDate" runat="server" Columns="18"
CssClass="text"></asp:TextBox>
<asp:CustomValidator id="MondayValidator1" runat="server"
ClientValidationFunction="ValidateMondayVB"
ErrorMessage="The Date is not a Monday" Enabled="False"
ControlToValidate="txtDate">*</asp:CustomValidator>
<script language="vbscript">
Sub ValidateMondayVB(source, args)
If IsDate(document.forms("Form1").item("<%= Me.txtDate.ClientID
%>").Value) then
startDt = CDate(document.forms("Form1").item("<%= Me.txtDate.ClientID
%>").Value)
msgbox "Here I am control <%= Me.ClientID %>, box = <%=
Me.txtDate.ClientID %> , source.id = " & source.id
If W
msgbox "Start date must be a Monday. You specified a " &
W
args.IsValid = false
Else
args.IsValid = true
End if
End if
End Sub
</script>
-- ASPX ends here --
Next add the following property to the control code behind:
Public Property MondayValidator() As CustomValidator
Get
Return MondayValidator1
End Get
Set(ByVal Value As CustomValidator)
MondayValidator1 = Value
End Set
End Property
--
Now create a test page using the control:
-- test page ASPX starts here --
<%@. Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm12.aspx.vb" Inherits="test1.WebForm12"%>
<%@. Register TagPrefix="uc1" TagName="CalendarTest" src="http://pics.10026.com/?src=CalendarTest.ascx"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm12</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:ValidationSummary id="ValidationSummary1" runat="server"
BorderStyle="Outset" Width="272px"></asp:ValidationSummary>
<P>
<uc1:CalendarTest id="CalendarTest1"
runat="server"></uc1:CalendarTest>
<uc1:CalendarTest id="CalendarTest2"
runat="server"></uc1:CalendarTest></P>
<P> </P>
<P>
<asp:Button id="Button1" runat="server" Text="Validate"></asp:Button></P>
</form>
</body>
</HTML>
-- test page ASPX ends here --
Finally add the following to the test page's Page_Load
CalendarTest1.MondayValidator.Enabled = True
CalendarTest1.MondayValidator.ErrorMessage = "Test1 Fired"
CalendarTest2.MondayValidator.Enabled = False
CalendarTest2.MondayValidator.ErrorMessage = "Test2 Fired"
Now run the project. Enter a Monday date (2/20/2006 for example) in the
first box. Enter a non-Monday date in the second. (In my actual work, thes
e
boxes would have Javascript formatting routines forcing a mm/dd/yyyy format
so only use that.) Now press the button. The first validator fires after
apparently using the 2nd instances VBscript sub, or so it looks to me.
Thanks
"Peter Blum" wrote:
> Please post:
> 1. The ASP.NET definitions of the controls involved.
> 2. The server side code involved.
> 3. The client-side code involved.
> -- Peter Blum
> www.PeterBlum.com
> Email: PLBlum@.PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
> "B. Chernick" <BChernick@.discussions.microsoft.com> wrote in message
> news:4AC9AE8B-E970-4340-AAD3-EB49500ED8A0@.microsoft.com...
>
>