Showing posts with label controls. Show all posts
Showing posts with label controls. Show all posts

Saturday, March 31, 2012

Submitting form with multiple onclick events

Hi

I'm building a custom control which basically takes data from the user
and then submits it. I would use the validator controls but if I
understand correctly (I've been working with .Net for 2 weeks) you
cant 'embed' them in the custom controls. Someone correct me if I'm
wrong (and please point to an example :) )

So, to get around this, I'm using Javascript. In my control, I'm doing

Writer.WriteAttribute("OnClick", "javascript:checkData();" &
Page.GetPostBackEventReference(Me, "Data"))

for an Input item so I get something like

<input type="button" value="Submit"
OnClick="javascript:checkData();__doPostBack('MyControl','D ata')" /
The checkData() function does this:

function checkLogin()
{
if (document.Data.item1.value == "" )
{
alert("Please enter item 1.");
return false;
}

if (document.Data.item2.value == "" )
{
alert("Please enter item 2.");
return false;
}

if (document.Data.item1.value != "" && document.Data.item2.value !=
"" )
{
return true;
}

}

My query is, how do I get the click event to fire correctly so that i
get alerts when there is a problem, and it passes through and submits
the form if there isnt a problem?

Thanks

SamHi,

Your client side script should use cancelBubble and returnValue to
disable event default process and raise alert if error found.

function CallServer()
{
if validate
{
__doPostBack('MyControl','Data');
}
else
{
alert("Error");
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}

HTH

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Natty Gur <natty@.dao2com.com> wrote in message news:<uSSwHLhAEHA.3348@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> Your client side script should use cancelBubble and returnValue to
> disable event default process and raise alert if error found.
> function CallServer()
> {
> if validate
> {
> __doPostBack('MyControl','Data');
> }
> else
> {
> alert("Error");
> window.event.cancelBubble = true;
> window.event.returnValue = false;
> }
> }
>
> HTH
> Natty Gur[MVP]
> blog : http://weblogs.asp.net/ngur
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Thanks Natty

This means I have to create inline javascripts which I'd rather not do
if I can help it. Just as luck would have it, after spending an 'hour
or two' trying to find a solution before posting, 5 mins after posting
I find a solution :( Always the way...

Anyhow, just for reference purposes, what I've done is to validate on
OnMouseDown and postback on OnClick. Works a treat
Hi Samuel,

Its unfortunate that you had to rework validation because of some incorrect
information about validators. The ASP.NET validators work fine within custom
controls. They have one key limitation related to their "location": the
ControlToValidate must be associated with the ID of a control in the same
"naming container". If your custom control impliments INamingContainer,
ControlToValidate can only point to other controls within your custom
control. If not, it can refer to other controls in the same naming container
that your custom control appears. Some types of naming containers: Page,
UserControl, and rows in DataGrid and DataList.

If you wanted to support validation without naming container limits, I wrote
a replacement to Microsoft's validators that overcomes that limitation among
numerous others: Professional Validation And More.
http://www.peterblum.com/vam/home.aspx.

-- Peter Blum
www.PeterBlum.com
Email: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Samuel Hon" <noreply@.samuelhon.co.uk> wrote in message
news:c8672b7d.0403040703.c458604@.posting.google.co m...
> Hi
> I'm building a custom control which basically takes data from the user
> and then submits it. I would use the validator controls but if I
> understand correctly (I've been working with .Net for 2 weeks) you
> cant 'embed' them in the custom controls. Someone correct me if I'm
> wrong (and please point to an example :) )
> So, to get around this, I'm using Javascript. In my control, I'm doing
> Writer.WriteAttribute("OnClick", "javascript:checkData();" &
> Page.GetPostBackEventReference(Me, "Data"))
> for an Input item so I get something like
> <input type="button" value="Submit"
> OnClick="javascript:checkData();__doPostBack('MyControl','D ata')" />
> The checkData() function does this:
> function checkLogin()
> {
> if (document.Data.item1.value == "" )
> {
> alert("Please enter item 1.");
> return false;
> }
> if (document.Data.item2.value == "" )
> {
> alert("Please enter item 2.");
> return false;
> }
> if (document.Data.item1.value != "" && document.Data.item2.value !=
> "" )
> {
> return true;
> }
> }
> My query is, how do I get the click event to fire correctly so that i
> get alerts when there is a problem, and it passes through and submits
> the form if there isnt a problem?
> Thanks
> Sam
"Peter Blum" <PLBlum@.Blum.info> wrote in message news:<OC#ZP$uAEHA.624@.TK2MSFTNGP10.phx.gbl>...
> Hi Samuel,
> Its unfortunate that you had to rework validation because of some incorrect
> information about validators. The ASP.NET validators work fine within custom
> controls. They have one key limitation related to their "location": the
> ControlToValidate must be associated with the ID of a control in the same
> "naming container". If your custom control impliments INamingContainer,
> ControlToValidate can only point to other controls within your custom
> control. If not, it can refer to other controls in the same naming container
> that your custom control appears. Some types of naming containers: Page,
> UserControl, and rows in DataGrid and DataList.
> If you wanted to support validation without naming container limits, I wrote
> a replacement to Microsoft's validators that overcomes that limitation among
> numerous others: Professional Validation And More.
> http://www.peterblum.com/vam/home.aspx.
> -- Peter Blum
> www.PeterBlum.com
> Email: PLBlum@.PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
<snip
Thanks Peter for clearing that up, I will re-investigate

Sam

Monday, March 26, 2012

Suggestion regarding Top/footer includes

Hello,

I have the following situation. On all of my pages I would like to include a top and footer ascx file. Therefore I created two user controls. Now the the top.ascx contains another usercontrol which is a menu and shown in a table and each link in that menu is seperated with a line break. Somethin like this:

link1
link2
link3
...

Now this menu is in a table. The table looks like this:

<table width="100%">
<tbody>
<tr valign="top">
<td width="15%">
MENU HERE
</td>
<td>
CONTENT WILL BE HERE
</td>
</tr>
</tbody>
</table
Now I need to get rid of everything what comes after the MENU HERE <TD>, because this will be used for my main content. and the table will be closed then in the footer. However webmatrix always adds the missing html tags and therefore my table always looks like shown above. I hope that you guys understand what I mean. Is there anything I can do or is this is the wrong way?

ThanksI recommend that you use MasterPages, where you place the footer/header in that template.

Regards.
Arent MasterPages only in 2.0? I am using 1.1.
Nop, try to download this forum code and see how master pages are being used.

regards.
Thanks haider_balal,

I can imagine that the code for this forum is complicated and that it contains a lot of stuff. Isnt there an easier article which explains master pages in 1.1?
Hello, try to check this and give me your opinion:

MasterPages Templating Framework

regards.
2.0 will be so much fun
Why wait till asp.net 2.0 ? We can still use it in 1.1 !!!!!

regards.

Saturday, March 24, 2012

suggestions?

I want to design an asp.net page which will have multiple controls. I want
to fill one of the control when there is some action like selecting
something from its previous control...I want to simulate as if its a windows
based application and the entire page is not refereshed (trip to
server)...other controls are not involved for this task...how can I
smoothly refresh these contols...I was reading about VIEWSTATE, is that the
solution to my problem...
ThanksYou'd use client side javascript for this. Search on dropdown list
and dependent in google for examples.
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx
"abcd" <abcd@.abcd.com> wrote in message
news:elV6cUQTFHA.3620@.TK2MSFTNGP09.phx.gbl...
>I want to design an asp.net page which will have multiple controls. I want
>to fill one of the control when there is some action like selecting
>something from its previous control...I want to simulate as if its a
>windows based application and the entire page is not refereshed (trip to
>server)...other controls are not involved for this task...how can I
>smoothly refresh these contols...I was reading about VIEWSTATE, is that the
>solution to my problem...
> Thanks
>

suggestions?

I want to design an asp.net page which will have multiple controls. I want
to fill one of the control when there is some action like selecting
something from its previous control...I want to simulate as if its a windows
based application and the entire page is not refereshed (trip to
server)...other controls are not involved for this task...how can I
smoothly refresh these contols...I was reading about VIEWSTATE, is that the
solution to my problem...

ThanksYou'd use client side javascript for this. Search on dropdown list
and dependent in google for examples.

--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx

"abcd" <abcd@.abcd.com> wrote in message
news:elV6cUQTFHA.3620@.TK2MSFTNGP09.phx.gbl...
>I want to design an asp.net page which will have multiple controls. I want
>to fill one of the control when there is some action like selecting
>something from its previous control...I want to simulate as if its a
>windows based application and the entire page is not refereshed (trip to
>server)...other controls are not involved for this task...how can I
>smoothly refresh these contols...I was reading about VIEWSTATE, is that the
>solution to my problem...
> Thanks

Super weird problem

I have a really strange problem. I've implemented a website using a lot of user controls (ascx). Everything worked fine before, and it has run for months.

And today, suddenly all those user controls (scrolling messages, tabstrips, menu, etc) don't work anymore, i.e. nothing appears although there's no error message. And I do not change anything, the codes remain exactly the same as before.

The web controls (textBox, calendar, buttons, etc) on the main page (not in ascx) still work fine.

I've spent, in vain, a lot of hours trying to figure it out. Do you have an idea what's going wrong ? I really appreciate your help.

Thanks

Btw, the codes are quite long, so I won't post it here. But if you need to see a part of it, just let me know, I'll post it.> nothing appears although there's no error message.

What exactly do you mean, "nothing appears"? If you View > Source, what do you see? Have the ASCX controls not be added at all? Or have they been added but not rendered?

Also, the elements you mention as having ceased to work look as though they'd use Javascript. Even if you haven't changed the ASCX or ASPX files, have you perhaps changed an external javascript file? I once forgot to add ";" to the end of a new line of script ... and it broke myentire site!
Things always get broken when no one has changed anything :)

If truly nothing has changed, try resetting IIS, as something might be confused in there...

Most likely though, as SomeNewKid2 said, it might be possible you made a change to something and didn't think it would even affect the controls...

But I could be wrong too :)
If the site is being hosted, I would check with the hosting site that they haven't upgraded the .net framework to 1.1.

Thursday, March 22, 2012

Support for Com Controls in Shared Hosting Services

Hi,
For my ASP.NET 2.0 website, I found what looks like a really great freeware
text editor (XStandard: http://xstandard.com/default.asp) but it is a COM
component. I've never set up a website and I'm not sure I want to invest a
couple of days on this control and find out it is not supported. I talked to
someone at webhost4life and he said 'it shouldn't be a problem' and I don't
like the 'shouldn't' word. I'm just wondering: should I be worried about
this or do all the web hosting companies support third-party COM controls
like this as a matter of course?
The XStandard control is a text editor. One of the things I like about it is
that it does not give the user a whole slough of buttons so he can choose
any font, any color of the rainbow or format his text in thousands of ways.
It lets you define the formatting options and presents them in a combo box.
Pretty clever.
Thanks.
Steveas the active/x control is installed on the client machine, not the
server you should be ok.
-- bruce (sqlwork.com)
Uriah Piddle wrote:
> Hi,
> For my ASP.NET 2.0 website, I found what looks like a really great freewar
e
> text editor (XStandard: http://xstandard.com/default.asp) but it is a COM
> component. I've never set up a website and I'm not sure I want to invest a
> couple of days on this control and find out it is not supported. I talked
to
> someone at webhost4life and he said 'it shouldn't be a problem' and I don'
t
> like the 'shouldn't' word. I'm just wondering: should I be worried about
> this or do all the web hosting companies support third-party COM controls
> like this as a matter of course?
> The XStandard control is a text editor. One of the things I like about it
is
> that it does not give the user a whole slough of buttons so he can choose
> any font, any color of the rainbow or format his text in thousands of ways
.
> It lets you define the formatting options and presents them in a combo box
.
> Pretty clever.
> Thanks.
> Steve
>

Support for Com Controls in Shared Hosting Services

Hi,

For my ASP.NET 2.0 website, I found what looks like a really great freeware
text editor (XStandard: http://xstandard.com/default.asp) but it is a COM
component. I've never set up a website and I'm not sure I want to invest a
couple of days on this control and find out it is not supported. I talked to
someone at webhost4life and he said 'it shouldn't be a problem' and I don't
like the 'shouldn't' word. I'm just wondering: should I be worried about
this or do all the web hosting companies support third-party COM controls
like this as a matter of course?

The XStandard control is a text editor. One of the things I like about it is
that it does not give the user a whole slough of buttons so he can choose
any font, any color of the rainbow or format his text in thousands of ways.
It lets you define the formatting options and presents them in a combo box.
Pretty clever.

Thanks.

Steveas the active/x control is installed on the client machine, not the
server you should be ok.

-- bruce (sqlwork.com)

Uriah Piddle wrote:

Quote:

Originally Posted by

Hi,
>
For my ASP.NET 2.0 website, I found what looks like a really great freeware
text editor (XStandard: http://xstandard.com/default.asp) but it is a COM
component. I've never set up a website and I'm not sure I want to invest a
couple of days on this control and find out it is not supported. I talked to
someone at webhost4life and he said 'it shouldn't be a problem' and I don't
like the 'shouldn't' word. I'm just wondering: should I be worried about
this or do all the web hosting companies support third-party COM controls
like this as a matter of course?
>
The XStandard control is a text editor. One of the things I like about it is
that it does not give the user a whole slough of buttons so he can choose
any font, any color of the rainbow or format his text in thousands of ways.
It lets you define the formatting options and presents them in a combo box.
Pretty clever.
>
Thanks.
>
Steve
>
>

Tuesday, March 13, 2012

Survey dynamic ASP server controls generation plz

How can i add dynamic survey questioners with (Text box, Check box and combo boxs). i am using ASP.NET 2.0,SQL2005.

If you have any good articles are ideas please share.

Thanks in advance

DK

Hi DK,

There are ASP.NET survey/poll controls. You can search them yourself.

http://www.codeproject.com/useritems/Site_Poll_Control.asp

But I'm not sure if it is dynamic.

Swapping programmatically created user controls?

Hello all,

I have a form in which I'm trying to load a user control depending on
some user choice, and my control's events are not firing properly.
Here's a completely stripped down repro of the problem:

The form itself is empty:
<body>
<form id="form1" runat="server" />
</body>

and here's the code behind for the form:
protected override void OnInit( EventArgs e )
{
string currentControl = "UC1";
object objCurrentControl = Session["CurrentControl"];
if( objCurrentControl != null )
currentControl = (string)objCurrentControl;

form1.Controls.Add( LoadControl( currentControl + ".ascx" ) );
}

The first user control:
===============
<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="UC1.ascx.cs"
Inherits="UC1" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC2" />

and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC2.ascx" );
ctl.ID = "UC2";
Parent.Controls.Add( ctl );
HttpContext.Current.Session["CurrentControl"] = "UC2";
Parent.Controls.Remove( this );
}

The second user control:
==================
<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="UC2.ascx.cs"
Inherits="UC2" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC1" />

and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC1.ascx" );
ctl.ID = "UC1";
Parent.Controls.Add( ctl );
Parent.Controls.Remove( this );
HttpContext.Current.Session["CurrentControl"] = "UC1";
}

and here's the problem:
When I run this, the page loads fine, with UC1. I click on the button
in UC1, the form gets posted, and comes back with UC2. Now if I click
on the button in UC2, the form gets posted, but comes back with UC2
itself instead of UC1. I click on the button in UC2 again, and now the
form comes back with UC1! It seems that the control loads fine, but the
button click event defined inside the user control will not fire the
first time, but only the second time.

I'm from the WinForms world and I'm new to the WebForms, so I might be
missing something obvious. Could anyone kindly point out what I'm doing
wrong? I've been scratching my head for the past two days without
making any progress. Thanks a lot in advance for your time.

- Ramesh.Hi,

I solved the problem myself. All I had to do was change the OnInit of
the form to set the ID of the control as well, like this:

protected override void OnInit( EventArgs e )
{
string currentControl = "UC1";
object objCurrentControl = Session["CurrentControl"];
if( objCurrentControl != null )
currentControl = (string)objCurrentControl;

Control ctl = LoadControl( currentControl + ".ascx" );
ctl.ID = currentControl;
form1.Controls.Add( ctl );
}

and it works fine now. I knew I was missing something obvious... Sorry
if I had wasted your time.

This approach, with an Atlas UpdatePanel thrown in to enclose the user
controls, results in a very WinForms like feel. Wow!

- Ramesh

Ramesh wrote:

Quote:

Originally Posted by

Hello all,
>
I have a form in which I'm trying to load a user control depending on
some user choice, and my control's events are not firing properly.
Here's a completely stripped down repro of the problem:
>
The form itself is empty:
<body>
<form id="form1" runat="server" />
</body>
>
and here's the code behind for the form:
protected override void OnInit( EventArgs e )
{
string currentControl = "UC1";
object objCurrentControl = Session["CurrentControl"];
if( objCurrentControl != null )
currentControl = (string)objCurrentControl;
>
form1.Controls.Add( LoadControl( currentControl + ".ascx" ) );
}
>
>
The first user control:
===============
<%@. Control Language="C#" AutoEventWireup="true" CodeFile="UC1.ascx.cs"
Inherits="UC1" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC2" />
>
and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC2.ascx" );
ctl.ID = "UC2";
Parent.Controls.Add( ctl );
HttpContext.Current.Session["CurrentControl"] = "UC2";
Parent.Controls.Remove( this );
}
>
The second user control:
==================
<%@. Control Language="C#" AutoEventWireup="true" CodeFile="UC2.ascx.cs"
Inherits="UC2" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC1" />
>
and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC1.ascx" );
ctl.ID = "UC1";
Parent.Controls.Add( ctl );
Parent.Controls.Remove( this );
HttpContext.Current.Session["CurrentControl"] = "UC1";
}
>
and here's the problem:
When I run this, the page loads fine, with UC1. I click on the button
in UC1, the form gets posted, and comes back with UC2. Now if I click
on the button in UC2, the form gets posted, but comes back with UC2
itself instead of UC1. I click on the button in UC2 again, and now the
form comes back with UC1! It seems that the control loads fine, but the
button click event defined inside the user control will not fire the
first time, but only the second time.
>
I'm from the WinForms world and I'm new to the WebForms, so I might be
missing something obvious. Could anyone kindly point out what I'm doing
wrong? I've been scratching my head for the past two days without
making any progress. Thanks a lot in advance for your time.
>
- Ramesh.